Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting a process on M1(ARM) CPU is 10 times slower than on Intel CPU #67591

Open
DanPristupov opened this issue Apr 5, 2022 · 7 comments
Open

Comments

@DanPristupov
Copy link

Description

I noticed that starting and running a process on M1 (ARM) CPU is 10 times slower than on Intel CPU.

Configuration

I made measures on MacOS on MBP16 Intel and MBP16 M1 Max (both are the latest available models at the moment).

I run /bin/ls as an example, but it can be any other process, for example /bin/date

using System.Diagnostics;
using System.Text;

Console.WriteLine("Start processes");
Run(16, "/bin/ls");

void Run(int count, string fileName)
{
    var stopWatch = Stopwatch.StartNew();
    for (var i = 0; i < count; i += 1)
    {
        RunProcess(fileName);
    }
    Console.WriteLine($"Total {stopWatch.Elapsed.TotalMilliseconds}");
}

void RunProcess(string fileName)
{
    var stopWatch = Stopwatch.StartNew();

    using (var process = new Process())
    {
        process.StartInfo = new ProcessStartInfo
        {
            FileName = fileName,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            ErrorDialog = false,
            CreateNoWindow = true,
            RedirectStandardInput = true,
            StandardOutputEncoding = Encoding.UTF8,
        };

        process.Start();

        var output = process.StandardOutput.ReadToEnd();

        process.WaitForExit();
    }
    Console.WriteLine($"{fileName}: {stopWatch.Elapsed.TotalMilliseconds}");
}

Data

Intel (2.5 ms avg)

dotnet run --release
Start processes
/bin/ls: 25.0932
/bin/ls: 3.6286
/bin/ls: 3.565
/bin/ls: 3.6467
/bin/ls: 2.3761
/bin/ls: 2.3586
/bin/ls: 2.5641
/bin/ls: 2.4136
/bin/ls: 2.3298
/bin/ls: 2.2895
/bin/ls: 2.2861
/bin/ls: 2.274
/bin/ls: 2.2964
/bin/ls: 2.346
/bin/ls: 2.2755
/bin/ls: 2.3004
Total 65.3108
Done!

M1 (25ms avg)

dotnet run --release
Start processes
/bin/ls: 100.2816
/bin/ls: 26.076
/bin/ls: 21.451
/bin/ls: 23.9278
/bin/ls: 21.1879
/bin/ls: 24.8415
/bin/ls: 25.9347
/bin/ls: 22.8774
/bin/ls: 42.4205
/bin/ls: 21.7012
/bin/ls: 23.1033
/bin/ls: 23.0439
/bin/ls: 20.8563
/bin/ls: 21.0834
/bin/ls: 20.9084
/bin/ls: 25.0697
Total 468.7015
Done!

P.S. You might be interested in seeing the roots of that issue: #67506

@DanPristupov DanPristupov added the tenet-performance Performance related issue label Apr 5, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Diagnostics.Process untriaged New issue has not been triaged by the area owner labels Apr 5, 2022
@ghost
Copy link

ghost commented Apr 5, 2022

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I noticed that starting and running a process on M1 (ARM) CPU is 10 times slower than on Intel CPU.

Configuration

I made measures on MacOS on MBP16 Intel and MBP16 M1 Max (both are the latest available models at the moment).

I run /bin/ls as an example, but it can be any other process, for example /bin/date

using System.Diagnostics;
using System.Text;

Console.WriteLine("Start processes");
Run(16, "/bin/ls");

void Run(int count, string fileName)
{
    var stopWatch = Stopwatch.StartNew();
    for (var i = 0; i < count; i += 1)
    {
        RunProcess(fileName);
    }
    Console.WriteLine($"Total {stopWatch.Elapsed.TotalMilliseconds}");
}

void RunProcess(string fileName)
{
    var stopWatch = Stopwatch.StartNew();

    using (var process = new Process())
    {
        process.StartInfo = new ProcessStartInfo
        {
            FileName = fileName,
            UseShellExecute = false,
            RedirectStandardOutput = true,
            ErrorDialog = false,
            CreateNoWindow = true,
            RedirectStandardInput = true,
            StandardOutputEncoding = Encoding.UTF8,
        };

        process.Start();

        var output = process.StandardOutput.ReadToEnd();

        process.WaitForExit();
    }
    Console.WriteLine($"{fileName}: {stopWatch.Elapsed.TotalMilliseconds}");
}

Data

Intel (2.5 ms avg)

dotnet run --release
Start processes
/bin/ls: 25.0932
/bin/ls: 3.6286
/bin/ls: 3.565
/bin/ls: 3.6467
/bin/ls: 2.3761
/bin/ls: 2.3586
/bin/ls: 2.5641
/bin/ls: 2.4136
/bin/ls: 2.3298
/bin/ls: 2.2895
/bin/ls: 2.2861
/bin/ls: 2.274
/bin/ls: 2.2964
/bin/ls: 2.346
/bin/ls: 2.2755
/bin/ls: 2.3004
Total 65.3108
Done!

M1 (25ms avg)

dotnet run --release
Start processes
/bin/ls: 100.2816
/bin/ls: 26.076
/bin/ls: 21.451
/bin/ls: 23.9278
/bin/ls: 21.1879
/bin/ls: 24.8415
/bin/ls: 25.9347
/bin/ls: 22.8774
/bin/ls: 42.4205
/bin/ls: 21.7012
/bin/ls: 23.1033
/bin/ls: 23.0439
/bin/ls: 20.8563
/bin/ls: 21.0834
/bin/ls: 20.9084
/bin/ls: 25.0697
Total 468.7015
Done!

P.S. You might be interested in seeing the roots of that issue: #67506

Author: DanPristupov
Assignees: -
Labels:

area-System.Diagnostics.Process, tenet-performance, untriaged

Milestone: -

@stephentoub
Copy link
Member

I assume you don't see such a difference if you just run the commands from the shell and time how long they take to invoke?

@EgorBo
Copy link
Member

EgorBo commented Apr 5, 2022

Seems like it got better in .NET 7.0:
image
(at least for x64)

@DanPristupov
Copy link
Author

@EgorBo may be I'm missing something, but the 'Apple M1 Max' processor on your screenshot is marked as 'Same'.

@EgorBo
Copy link
Member

EgorBo commented Apr 5, 2022

Sorry I didn't notice you were talking about M1 specifically

@adamsitnik
Copy link
Member

@DanPristupov can you observe the same difference if you run these commands from shell?

@DanPristupov
Copy link
Author

@adamsitnik

Intel (3ms):

time ls
ls  0.00s user 0.00s system 80% cpu 0.003 total

M1 (4ms):

time ls
ls  0.00s user 0.00s system 49% cpu 0.004 total

Is that what you ask?

@jeffhandley jeffhandley added this to the Future milestone Aug 2, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants