Created
November 7, 2011 15:56
-
-
Save ericmoritz/1345342 to your computer and use it in GitHub Desktop.
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
| *.class | |
| *.jar | |
| countby |
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
| (defn count-to [i n] | |
| (if (= i n) | |
| i | |
| (recur (inc i) n))) | |
| (println (time (count-to 0 1000000))) | |
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
| 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()); |
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
| 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 |
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
| #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); | |
| } |
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
| 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); | |
| } | |
| } |
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
| all: countby CountBy.class | |
| ./run.sh | |
| countby: | |
| gcc -o countby countby.c | |
| CountBy.class: | |
| javac CountBy.java | |
| clean: | |
| rm CountBy.class | |
| rm countby |
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
| C: | |
| 1000000 | |
| 2 | |
| Java: | |
| 1000000 | |
| 10 | |
| Python: | |
| 1000000 | |
| 85.3998661041 | |
| PyPy: | |
| 1000000 | |
| 3.0632019043 | |
| Node: | |
| 1000000 | |
| 5 | |
| Clojure: | |
| "Elapsed time: 35.947 msecs" | |
| 1000000 |
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
| 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