Created
October 5, 2010 16:18
-
-
Save edbond/611825 to your computer and use it in GitHub Desktop.
clojure memoize
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
Non-memoize | |
Cleaning JVM allocations ... | |
Warming up for JIT ... | |
Estimating execution count ... | |
Running ... | |
Checking GC... | |
Cleaning JVM allocations ... | |
Finding outliers ... | |
Bootstrapping ... | |
Checking outlier significance | |
amd64 Linux 2.6.32-23-generic 2 cpu(s) | |
OpenJDK 64-Bit Server VM 16.0-b13 | |
Runtime arguments: -Dswank.encoding=utf-8-unix -Dinput.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dclojure.compile.path=/home/eduard/clojure101/classes | |
Evaluation count : 1175340 | |
Execution time mean : 51.577383 us 95.0% CI: (51.573471 us, 51.580773 us) | |
Execution time std-deviation : 64.661590 us 95.0% CI: (64.133906 us, 65.270937 us) | |
Found 3 outliers in 60 samples (5.0000 %) | |
low-severe 3 (5.0000 %) | |
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers | |
Memoizing | |
Cleaning JVM allocations ... | |
Warming up for JIT ... | |
Estimating execution count ... | |
Running ... | |
Checking GC... | |
Cleaning JVM allocations ... | |
Finding outliers ... | |
Bootstrapping ... | |
Checking outlier significance | |
amd64 Linux 2.6.32-23-generic 2 cpu(s) | |
OpenJDK 64-Bit Server VM 16.0-b13 | |
Runtime arguments: -Dswank.encoding=utf-8-unix -Dinput.encoding=UTF-8 -Dfile.encoding=UTF-8 -Dclojure.compile.path=/home/eduard/clojure101/classes | |
Evaluation count : 1710180 | |
Execution time mean : 35.326952 us 95.0% CI: (35.323946 us, 35.329203 us) | |
Execution time std-deviation : 57.833058 us 95.0% CI: (57.365573 us, 58.260308 us) | |
Found 5 outliers in 60 samples (8.3333 %) | |
low-severe 5 (8.3333 %) | |
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers |
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
(ns clojure101.w1e4 | |
(:use [criterium.core])) | |
; Phi = (1 + sqrt(5)) / 2 | |
(def phi (/ (+ 1 (Math/sqrt 5)) 2)) | |
; Fib(n) = round(Phi^n / sqrt(5)) | |
(defn nth-fib | |
[n] | |
(bigint (/ (Math/pow phi n) (Math/sqrt 5)))) | |
(def memoize-nth-fib (memoize nth-fib)) | |
(defn bench1 | |
[] | |
(do | |
(println "Non-memoize") | |
(with-progress-reporting | |
(bench (doall (map nth-fib (range 10 100))) :verbose)) | |
(println "Memoizing") | |
(with-progress-reporting | |
(bench (doall (map memoize-nth-fib (range 10 100))) :verbose)))) | |
(time (dotimes [i 100000] (doall (map nth-fib (range 10 100))))) | |
(time (dotimes [i 100000] (doall (map memoize-nth-fib (range 10 100))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment