Last active
August 29, 2015 14:13
-
-
Save swannodette/45d06564fb3b3b9a5c52 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
// lein cljsbuild once release | |
// d8 node_modules/immutable/dist/immutable.min.js mori.bare.js ./bench/mut_perf.js | |
// jsc node_modules/immutable/dist/immutable.min.js mori.bare.js ./bench/mut_perf.js | |
;(function() { | |
function sum(a,b) { | |
return a+b; | |
} | |
var m = mori; | |
var runs = []; | |
for(var j = 0; j < 10; j++) { | |
var s = new Date(); | |
var arr = []; | |
for(var i = 0; i < 1000000; i++) { | |
if(i % 32 == 0) { | |
arr.push(Math.random()); | |
} else { | |
arr.push(i); | |
} | |
} | |
var el = (new Date())-s; | |
runs.push(el); | |
print("Array push " + arr.length + " items " + el + " " + arr.reduce(sum, 0)); | |
} | |
print(runs.reduce(sum,0)/10); | |
// runs = []; | |
// for(var j = 0; j < 10; j++) { | |
// s = new Date(); | |
// var v = m.vector(); | |
// for(var i = 0; i < 1000000; i++) { | |
// if(i % 32 === 0) { | |
// v = m.conj1(v, Math.random()); | |
// } else { | |
// v = m.conj1(v, i); | |
// } | |
// } | |
// var el = (new Date())-s; | |
// runs.push(el); | |
// print("Persistent vector conj " + m.count(v) + " items " + el + " " + m.reduce(sum,0,v)); | |
// } | |
// print(runs.reduce(sum,0)/10); | |
runs = []; | |
for(var j = 0; j < 10; j++) { | |
s = new Date(); | |
var mv = m.mutable.thaw(m.vector()); | |
for(var i = 0; i < 1000000; i++) { | |
if(i % 32 === 0) { | |
mv = m.mutable.conj1(mv, Math.random()); | |
} else { | |
mv = m.mutable.conj1(mv, i); | |
} | |
} | |
var v = m.mutable.freeze(mv); | |
var el = (new Date())-s; | |
runs.push(el); | |
print("Mutable vector conj " + m.count(v) + " items " + el + " " + m.reduce(sum,0,v)); | |
} | |
print(runs.reduce(sum,0)/10); | |
runs = []; | |
for(var j = 0; j < 10; j++) { | |
s = new Date(); | |
var l = Immutable.List().withMutations(function(ml) { | |
for(var i = 0; i < 1000000; i++) { | |
if(i % 32 === 0) { | |
ml.push(Math.random()); | |
} else { | |
ml.push(i); | |
} | |
} | |
}); | |
var el = (new Date())-s; | |
runs.push(el); | |
print("Mutable list push " + l.size + " items " + el + " " + l.reduce(sum, 0)); | |
} | |
print(runs.reduce(sum,0)/10); | |
})(); | |
// Macbook Pro 2.26ghz, d8 3.29.80 | |
// Array push 1000000 items 225 484375015598.72327 | |
// Array push 1000000 items 182 484375015658.3886 | |
// Array push 1000000 items 106 484375015676.13965 | |
// Array push 1000000 items 192 484375015552.31647 | |
// Array push 1000000 items 214 484375015576.26776 | |
// Array push 1000000 items 213 484375015621.9111 | |
// Array push 1000000 items 232 484375015642.3849 | |
// Array push 1000000 items 285 484375015725.9055 | |
// Array push 1000000 items 252 484375015554.97125 | |
// Array push 1000000 items 227 484375015716.7778 | |
// 212.8 | |
// Mutable vector conj 1000000 items 111 484375015691.779 | |
// Mutable vector conj 1000000 items 70 484375015619.4253 | |
// Mutable vector conj 1000000 items 53 484375015673.2537 | |
// Mutable vector conj 1000000 items 90 484375015680.48517 | |
// Mutable vector conj 1000000 items 65 484375015581.82574 | |
// Mutable vector conj 1000000 items 57 484375015652.67017 | |
// Mutable vector conj 1000000 items 54 484375015679.46674 | |
// Mutable vector conj 1000000 items 66 484375015737.9629 | |
// Mutable vector conj 1000000 items 65 484375015626.65576 | |
// Mutable vector conj 1000000 items 54 484375015650.9963 | |
// 68.5 | |
// Mutable list push 1000000 items 397 484375015660.624 | |
// Mutable list push 1000000 items 378 484375015652.5248 | |
// Mutable list push 1000000 items 430 484375015570.18585 | |
// Mutable list push 1000000 items 378 484375015679.4106 | |
// Mutable list push 1000000 items 374 484375015571.91034 | |
// Mutable list push 1000000 items 431 484375015630.1371 | |
// Mutable list push 1000000 items 361 484375015636.17334 | |
// Mutable list push 1000000 items 371 484375015593.2238 | |
// Mutable list push 1000000 items 372 484375015676.4787 | |
// Mutable list push 1000000 items 372 484375015494.54944 | |
386.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment