Skip to content

Instantly share code, notes, and snippets.

@Hamcha
Created October 19, 2012 15:11
Show Gist options
  • Save Hamcha/3918746 to your computer and use it in GitHub Desktop.
Save Hamcha/3918746 to your computer and use it in GitHub Desktop.
Benchmark.sh Results
__ JAVASCRIPT V8 (v8) __
real 0m0.658s
user 0m0.654s
sys 0m0.008s
__ NODE.JS (node) __
real 0m0.734s
user 0m0.721s
sys 0m0.016s
__ JS SPIDERMONKEY (js) __
real 0m10.691s
user 0m10.685s
sys 0m0.007s
__ PYTHON (python) __
real 0m14.843s
user 0m14.763s
sys 0m0.081s
__ PYTHON OPTIMIZED (python -O) __
real 0m14.796s
user 0m14.780s
sys 0m0.016s
__ PYTHON OPT. + JIT (pypy -O) __
real 0m1.398s
user 0m1.377s
sys 0m0.021s
__ JAVA (java) __
real 0m1.084s
user 0m1.905s
sys 0m0.069s
__ (GCC) UNOPTIMIZED C/++ (gcc) __
real 0m0.531s
user 0m0.529s
sys 0m0.003s
__ (GCC) OPTIMIZED C/++ (gcc -O3) __
real 0m0.336s
user 0m0.334s
sys 0m0.003s
__ (CLANG) OPTIMIZED C/++ (clang -O4) __
real 0m0.335s
user 0m0.333s
sys 0m0.003s
echo "__ JAVASCRIPT V8 (v8) __"
time shell_x64 primes.js | grep real
echo ""
echo "__ NODE.JS (node) __"
time node primes_node.js | grep real
echo ""
echo "__ JS SPIDERMONKEY (js) __"
time js primes.js | grep real
echo ""
echo "__ PYTHON (python) __"
time python primes.py | grep real
echo ""
echo "__ PYTHON OPTIMIZED (python -O) __"
time python -O primes.py | grep real
echo ""
echo "__ PYTHON OPT. + JIT (pypy -O) __"
time pypy -O primes.py | grep real
echo ""
echo "__ JAVA (java) __"
time java PrimeApp | grep real
echo ""
echo "__ (GCC) UNOPTIMIZED C/++ (gcc) __"
time ./primes | grep real
echo ""
echo "__ (GCC) OPTIMIZED C/++ (gcc -O3) __"
time ./a.out | grep real
echo ""
echo "__ (CLANG) OPTIMIZED C/++ (clang -O4) __"
time ./a.llvm | grep real
#include <stdio.h>
#define MAXN 250000
int primes[MAXN], curlen;
bool isDivisible(int n)
{
for (int i = 0; i < curlen; i++)
{
long current_prime = primes[i];
if (current_prime*current_prime > n) return false;
if (n % primes[i] == 0) return true;
}
return false;
}
int main()
{
curlen = 0;
int n = 2;
while (curlen < MAXN)
{
if (!isDivisible(n))
{
primes[curlen] = n;
curlen++;
}
n++;
}
printf("%d",--n);
}
class PrimeApp {
private static Integer[] primes;
private static Integer current, curlen;
private static Boolean isDivisible(Integer x)
{
for (Integer i = 0; i < curlen; i++)
{
Integer current_prime = primes[i];
if (current_prime*current_prime > x) return false;
if ((x % current_prime) == 0) return true;
}
return false;
}
public static void main(String[] args) {
primes = new Integer[250000];
current = 2;
curlen = 0;
while (curlen < 250000)
{
if (!PrimeApp.isDivisible(current))
{
primes[curlen] = current;
curlen++;
}
current++;
}
System.out.println(--current);
}
}
var primes = [];
var current = 2;
function isDivisible(n)
{
for (var i = 0; i < primes.length; i++)
{
var current_prime = primes[i];
if (current_prime * current_prime > n) return false;
if ((n % current_prime) == 0) return true;
}
return false;
}
while (primes.length < 250000)
{
if (!isDivisible(current)) primes.push(current);
current++;
}
print(--current);
primes = []
current = 2
found = 0
def isDivisible(x):
for p in primes:
if (p*p > x): return False
if (x % p) == 0: return True
return False
while found < 250000:
if not isDivisible(current):
primes.append(current)
found = found + 1
current = current + 1
print (current-1)
var primes = [];
var current = 2;
function isDivisible(n)
{
for (var i = 0; i < primes.length; i++)
{
var current_prime = primes[i];
if (current_prime * current_prime > n) return false;
if ((n % current_prime) == 0) return true;
}
return false;
}
while (primes.length < 250000)
{
if (!isDivisible(current)) primes.push(current);
current++;
}
console.log(--current);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment