Skip to content

Instantly share code, notes, and snippets.

@davars
Forked from drasch/results.txt
Last active December 13, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davars/4986846 to your computer and use it in GitHub Desktop.
Save davars/4986846 to your computer and use it in GitHub Desktop.
$ time ruby test.rb #1.8.7
Timing ruby_no_func - 14.397207
Timing ruby_func - 30.25229
real 0m44.720s
$ time ruby test.rb #1.9.3
Timing ruby_no_func - 6.197986
Timing ruby_func - 9.45756
real 0m15.769s
$ ruby test.rb #jruby 1.7.2
Timing ruby_no_func - 4.0
Timing ruby_func - 6.566
real 0m12.014s
user 0m13.675s # I included user time here, because in all other
# cases it was lower than real. This implies threading
$ time php test.php
# nah
$ time python test.py # 2.7.2
Timing <function python_no_func at 0x101323d70> - 7.607967
Timing <function python_func at 0x101339488> - 17.889498
real 0m26.833s
$ time pypy test.py
Timing <function python_no_func at 0x000000010384aa70> - 0.160570
Timing <function python_func at 0x000000010384ad40> - 0.260157
real 0m0.465s
$ time node test.js #v0.8.15
Timing No Func
Done 100000000 0.136
Timing Func
Done 100000000 0.13
real 0m0.307s
var timeme = function(desc, f) {
var start = +new Date;
console.log("Timing " + desc);
var a = f();
console.log("Done", a, ((+new Date) - start) / 1000);
};
var js_no_func = function() {
var a = 0;
for(var i = 0; i < 1000000000; i++) {
a = a + 1;
}
return a;
};
var js_func = function() {
var a = 0;
for(var i = 0; i < 1000000000; i++) {
a = add_one(a);
}
return a;
};
var add_one = function(a) {
return a + 1;
}
timeme("No Func", js_no_func);
timeme("Func", js_func);
<?php
function timeme($call) {
$start_time = microtime(true);
print "Timing $call";
$call();
$elapsed = microtime(true) - $start_time;
print " - $elapsed\n";
}
function php_no_func_call() {
$a =0;
for($i=0; $i< 100000000; $i ++) {
$a = $a + 1;
}
}
function php_func_call() {
$a =0;
for($i=0; $i< 100000000; $i ++) {
$a = add_one($a);
}
}
function add_one($a) {
return $a+1;
}
timeme("php_no_func_call");
timeme("php_func_call");
import time
def timeme(func):
start_time = time.time()
func()
print('Timing %s - %f' % (str(func), time.time() - start_time))
def python_no_func():
a = 0
for i in range(1, 100000000):
a = a + 1
def python_func():
a = 0
for i in range(1, 100000000):
a = add_one(a)
def add_one(a):
return a+1
timeme(python_no_func)
timeme(python_func)
require 'time'
def timeme(name)
start_time = Time.now
yield
stop_time = Time.now
puts "Timing #{name} - #{stop_time - start_time}"
end
def ruby_no_func
a = 0
100000000.times do
a = a + 1
end
end
def ruby_func
a = 0
100000000.times do
a = add_one(a)
end
end
def add_one(a)
a+1
end
timeme("ruby_no_func") {ruby_no_func}
timeme("ruby_func") {ruby_func}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment