The Dart Speed

The Dart Speed

The speed of a programming language is important, even if I rarely need it. I’m happy if the language I use is fast. Although Dart is not the fastest language on the market, I appreciate its cool and clean syntax. I have therefore compared the speed of Dart, JavaScript and Rust.

I think everyone knows that Rust will be the fastest. But in my speed test, the results really blew me away. So this article is not only for Dart developers, but also for Rust and JavaScript developers.

Benchmark

Thebenchmark evaluates the performance of a Fibonacci function. The function is run 100 times with an input of 35 in each script. Due to hardware limitations, higher input values cannot be tested on my laptop. The JavaScript code was executed with Deno. Now I will show you the Dart, JavaScript and Rust implementation.

How the benchmark was run:

I coded a small PowerShell script to run each program 10 times and give me the time for each execution, also calculating the average execution time. I tried to keep the environment relatively similar on each benchmark and also ran the benchmark 3 times to make sure the numbers were similar and there were no big gaps.

System Hardware: Processor: AMD Ryzen 7 4800H with Radeon Graphics 2.90 GHz Installed RAM: 16,0 GB (15,4 GB usable) System: Type 64-bit operating system, x64-based processor Windows: Windows 11 Home, Version 23H2

DISCLAIMER: THIS IS NOT A PROFESSIONAL BENCHMARK, IT IS ONLY TO GIVE AN INDICATION OF THE SPEED.

This is the PowerShell script:

# Prompting the user for the command to execute
$command = Read-Host "Enter the command to execute (e.g., 'py main.py')"

# Initializing total time variable
$totalTime = 0

# Running the command 10 times and calculating the total time
for ($i = 1; $i -lt 11; $i++) {
    $executionTime = Measure-Command { Invoke-Expression "& $command" }
    $totalTime += $executionTime.TotalMilliseconds
    Write-Host "Execution $i Time: $($executionTime.TotalMilliseconds) milliseconds"
}

# Calculating average time
$averageTime = $totalTime / 10
Write-Host "Average Execution Time: $averageTime milliseconds"        

Dart

JavaScript

Rust

As you can see, it is the same code, just translated between languages.

Results

Average: 9940.12497 ms Compared to Dart: 159 % slower Compared to Rust: 138.67 % slower

Average: 6221.07265 ms Compared to JavaScript:?159 % faster Compared to Rust: 86.79 % slower

Average: 71.67717 ms Compared to JavaScript: 138.67 % faster Compared to Dart: 86.79 % faster

Conclusion

If you just look at JavaScript and Dart, Dart looks like a fast language. Add Rust to the mix and you can see just how fast it can be. As a little motivation to all JavaScript developers, I could not include Python in this benchmark because the run never finished.

要查看或添加评论,请登录

monirul islam的更多文章

社区洞察

其他会员也浏览了