Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Last active July 13, 2021 17:42
Show Gist options
  • Save mertyildiran/d8fa39ea6fd6190d1ea057ec8ca4ffeb to your computer and use it in GitHub Desktop.
Save mertyildiran/d8fa39ea6fd6190d1ea057ec8ca4ffeb to your computer and use it in GitHub Desktop.
JIT compiled Chaos vs. Python, Ruby and PHP on recursive Fibonacci

fib(40) results:

$ hyperfine --warmup 3 \
	'chaos dev.kaos' \
	'python3 dev.py' \
	'ruby dev.rb' \
	'php dev.php'
Benchmark #1: chaos dev.kaos
  Time (mean ± σ):     954.4 ms ±   4.1 ms    [User: 953.6 ms, System: 0.5 ms]
  Range (min … max):   952.3 ms … 965.2 ms    10 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (956.3 ms). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.
 
Benchmark #2: python3 dev.py
  Time (mean ± σ):     14.443 s ±  0.947 s    [User: 14.436 s, System: 0.002 s]
  Range (min … max):   13.687 s … 15.806 s    10 runs
 
Benchmark #3: ruby dev.rb
  Time (mean ± σ):      4.732 s ±  0.030 s    [User: 4.725 s, System: 0.005 s]
  Range (min … max):    4.708 s …  4.815 s    10 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark #4: php dev.php
  Time (mean ± σ):      3.416 s ±  0.029 s    [User: 3.412 s, System: 0.004 s]
  Range (min … max):    3.393 s …  3.496 s    10 runs
 
  Warning: The first benchmarking run for this command was significantly slower than the rest (3.496 s). This could be caused by (filesystem) caches that were not filled until after the first run. You should consider using the '--warmup' option to fill those caches before the actual benchmark. Alternatively, use the '--prepare' option to clear the caches before each timing run.
 
Summary
  'chaos dev.kaos' ran
    3.58 ± 0.03 times faster than 'php dev.php'
    4.96 ± 0.04 times faster than 'ruby dev.rb'
   15.13 ± 0.99 times faster than 'python3 dev.py'

Chaos version: https://github.com/chaos-lang/chaos/commit/32c9af1f391d8b715b9441d13431d9b05bf867e8

Python version: 3.8.5

Ruby version: 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]

PHP version: 7.4.3 (cli) (built: Jul 5 2021 15:13:35) ( NTS )

num def sum(num j)
num x = fib(j - 1)
num y = fib(j - 2)
num z = x + y
return z
end
num def fib(num n)
end {
n < 3 : return 1,
default : sum(n)
}
print fib(40)
<?php
function fib($n)
{
return $n < 3 ? 1 : fib($n - 1) + fib($n - 2);
}
echo fib(40).PHP_EOL;
?>
def fib(n):
if n < 3:
return 1
else:
return fib(n-1) + fib(n-2)
print(fib(40))
def fib(n)
n <= 2 ? 1 : fib( n - 1 ) + fib( n - 2 )
end
puts fib(40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment