Last active
November 27, 2015 14:37
-
-
Save yorickpeterse/255593473d941b582167 to your computer and use it in GitHub Desktop.
This file contains 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
Numbers indicate the amount of iterations in 5 seconds. | |
The C example was compiled using: | |
clang -Wall -Wextra -pedantic -O2 test.c -o test | |
Results: | |
C: 2272688181 | |
LuaJIT 170557787 => ~13x slower | |
Lua 86128887 => ~26x slower (no JIT) | |
JRuby 9k 25726121 => ~88x slower (Invoke Dynamic, no JIT threshold) | |
JRuby 9k 23399982 => ~97x slower | |
rbx git 18267317 => ~124x slower | |
MRI 2.2.3 10886124 => ~208x slower (no JIT) |
This file contains 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
#include <stdio.h> | |
#include <time.h> | |
int main() { | |
volatile size_t a = 10; | |
volatile size_t b = 5; | |
size_t iterations = 0; | |
int start = (int) time(NULL); | |
while ( (((int) time(NULL)) - start) <= 5 ) { | |
size_t res = (a + b + iterations); | |
iterations++; | |
} | |
printf("Iterations: %lu\n", iterations); | |
return 0; | |
} |
This file contains 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
function measure() | |
local a = 10 | |
local b = 5 | |
local start = os.time() | |
local iterations = 0 | |
while (os.time() - start) <= 5 do | |
local res = a + b + iterations | |
iterations = iterations + 1 | |
end | |
return iterations | |
end | |
measure() | |
print("Iterations: " .. measure()) |
This file contains 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
def measure | |
a = 10 | |
b = 5 | |
start = Time.now | |
iterations = 0 | |
while (Time.now - start) <= 5 | |
res = a + b + iterations | |
iterations += 1 | |
end | |
iterations | |
end | |
measure | |
puts "Iterations: #{measure}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment