Created
September 23, 2011 01:36
-
-
Save ibdknox/1236554 to your computer and use it in GitHub Desktop.
Slow cljs loops
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
(ns cljs-test.client) | |
(defn now [] | |
(. (js/Date.) (getTime))) | |
(let [nums (doall (range 0 1000000)) | |
start (now)] | |
(doseq [n nums] | |
) | |
(. js/console (log (- (now) start)))) | |
;;4500-6500ms | |
(js* "var c = 0, start = cljs_test.client.now(); for(var i = 0; i < 1000000; i++) { c += i; }; console.log(cljs_test.client.now() - start);") | |
;;15-30ms |
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
(ns cljs-test.client) | |
(defn now [] | |
(. (js/Date.) (getTime))) | |
(let [start (now)] | |
(doseq [n (range 0 1000000)] | |
) | |
(. js/console (log (- (now) start)))) | |
;;4500-6500ms | |
(js* "var c = 0, start = cljs_test.client.now(); for(var i = 0; i < 1000000; i++) { c += i; }; console.log(cljs_test.client.now() - start);") | |
;;15-30ms |
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
(ns cljs-test.client) | |
(defn now [] | |
(. (js/Date.) (getTime))) | |
(let [nums (doall (range 0 1000000)) | |
start (now)] | |
(loop [n nums] | |
(when n | |
(recur (next n)))) | |
(. js/console (log (- (now) start)))) | |
;; Advanced mode output: | |
;;for(var sc = oc.call(f, mc.call(f, 0, 1E6)), tc = rc.call(f), uc = sc;;) { | |
;; if(s(uc)) { | |
;; uc = J.call(f, uc) | |
;; }else { | |
;; break | |
;; } | |
;;} | |
;; Advanced mode time: 1700-2000ms | |
(js* "var c = 0, start = cljs_test.client.now(); for(var i = 0; i < 1000000; i++) { c += i; }; console.log(cljs_test.client.now() - start);") | |
;;15-30ms |
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
(ns cljs-test.client) | |
(defn now [] | |
(. (js/Date.) (getTime))) | |
(let [start (now)] | |
(loop [n 0] | |
(when (< n 1000000) | |
(recur (inc n)))) | |
(. js/console (log (- (now) start)))) | |
;;120ms | |
(js* "var c = 0, start = cljs_test.client.now(); for(var i = 0; i < 1000000; i++) { c += i; }; console.log(cljs_test.client.now() - start);") | |
;;15-30ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment