Last active
December 11, 2015 05:08
-
-
Save drasch/4549843 to your computer and use it in GitHub Desktop.
testing ruby vs php function call performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Ruby | |
$ ruby test.rb #1.8.7 | |
Timing ruby_no_func - 11.53991 | |
Timing ruby_func - 24.726644 | |
real 0m37.154s | |
$ ruby test.rb #1.9.3 | |
Timing ruby_no_func - 5.672002329 | |
Timing ruby_func - 10.549024467 | |
real 0m16.283s | |
$ ruby test.rb #jruby 1.7.2 | |
Timing ruby_no_func - 3.118 | |
Timing ruby_func - 4.877 | |
real 0m9.458s | |
user 0m11.569s # I included user time here, because in all other | |
# cases it was lower than real. This implies threading | |
## Php | |
$ time php test.php | |
Timing php_no_func_call - 3.0001409053802 | |
Timing php_func_call - 12.884459972382 | |
real 0m16.008s | |
## Python | |
$ time python test.py | |
Timing <function python_no_func at 0x7ff4040dfa28> - 2.719969 | |
Timing <function python_func at 0x7ff4040dfaa0> - 7.844415 | |
real 0m10.584s | |
$ time pypy test.py | |
Timing <function python_no_func at 0x00007f72ef976f98> - 0.116669 | |
Timing <function python_func at 0x00007f72ef9771f0> - 0.146293 | |
real 0m0.297s | |
$ time jython test.py | |
Timing <function python_no_func at 0x2> - 2.212000 | |
Timing <function python_func at 0x3> - 6.868000 | |
real 0m10.701s | |
# JavaScript / Node.js | |
$ time nodejs test.js #node v0.9.9 | |
Timing No Func 0.123 | |
Timing Func 0.118 | |
real 0m0.284s | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timeme = function(desc, f) { | |
var start = +new Date; | |
f(); | |
console.log("Timing " + desc + " " + ((+new Date) - start)/1000.0); | |
}; | |
var js_no_func = function() { | |
var a = 0; | |
for(var i = 0; i < 100000000; i++) { | |
a = a + 1; | |
} | |
}; | |
var js_func = function() { | |
var a = 0; | |
for(var i = 0; i < 100000000; i++) { | |
a = add_one(a); | |
} | |
}; | |
var add_one = function(a) { | |
return a + 1; | |
} | |
timeme("No Func", js_no_func); | |
timeme("Func", js_func); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 xrange(1, 100000000): | |
a = a + 1 | |
def python_func(): | |
a = 0 | |
for i in xrange(1, 100000000): | |
a = add_one(a) | |
def add_one(a): | |
return a+1 | |
timeme(python_no_func) | |
timeme(python_func) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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