Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active November 27, 2015 14:37
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 yorickpeterse/255593473d941b582167 to your computer and use it in GitHub Desktop.
Save yorickpeterse/255593473d941b582167 to your computer and use it in GitHub Desktop.
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)
#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;
}
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())
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