Skip to content

Instantly share code, notes, and snippets.

@ericmoritz
Created November 7, 2011 15:56
Show Gist options
  • Select an option

  • Save ericmoritz/1345342 to your computer and use it in GitHub Desktop.

Select an option

Save ericmoritz/1345342 to your computer and use it in GitHub Desktop.
*.class
*.jar
countby
(defn count-to [i n]
(if (= i n)
i
(recur (inc i) n)))
(println (time (count-to 0 1000000)))
function count_to(n) {
var i = 0;
while(i < n) {
i = i + 1;
}
return i
}
var start = new Date();
var result = count_to(1000000);
var end = new Date();
console.log(result);
console.log(end.getTime() - start.getTime());
from time import time
def count_to(n):
i = 0
while i < n:
i = i + 1
return i
start = time()
result = count_to(1000000)
end = time()
print result
print (end - start) * 1000
#include <stdio.h>
#include <time.h>
#include <unistd.h>
long count_by(long n) {
long i = 0;
while(i < n) {
i++;
}
return i;
}
int main(int argc, char *argv[]) {
struct timeval start, end;
long elapsed, result;
gettimeofday(&start, NULL);
result = count_by(1000000);
gettimeofday(&end, NULL);
elapsed = (end.tv_usec - start.tv_usec) / 1000;
printf("%li\n", result);
printf("%li\n", elapsed);
}
class CountBy {
public static int countBy(int n) {
int i = 0;
while(i < n) {
i++;
}
return i;
}
public static void main(String [] args) {
int result;
long endTime, startTime;
startTime = System.currentTimeMillis();
result = CountBy.countBy(1000000);
endTime = System.currentTimeMillis();
System.out.println(result);
System.out.println(endTime - startTime);
}
}
all: countby CountBy.class
./run.sh
countby:
gcc -o countby countby.c
CountBy.class:
javac CountBy.java
clean:
rm CountBy.class
rm countby
C:
1000000
2
Java:
1000000
10
Python:
1000000
85.3998661041
PyPy:
1000000
3.0632019043
Node:
1000000
5
Clojure:
"Elapsed time: 35.947 msecs"
1000000
echo "C:"
./countby
echo
echo "Java:"
java CountBy
echo
echo "Python:"
python count.py
echo
echo "PyPy:"
pypy count.py
echo
echo "Node:"
node count.js
echo
echo "Clojure:"
java -cp clojure-1.3.0.jar clojure.main count.clj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment