git ssb

3+

cel / ssb-npm-registry



Tree: 4f27567900a7b5b821bccc74e95bfc96c8233159

Files: 4f27567900a7b5b821bccc74e95bfc96c8233159 / node_modules / hashlru / bench.js

994 bytesRaw
1var Stats = require('statistics/mutate')
2var LRU = require('./')
3
4//simple benchmarks, and measure standard deviation
5
6function run (N, op, init) {
7 var stats = null, value
8 for(var j = 0; j < 100; j++) {
9 if(init) value = init(j)
10 var start = Date.now()
11 for(var i = 0; i < N; i++) op(value, i)
12 stats = Stats(stats, N/((Date.now() - start)))
13 }
14 return stats
15}
16
17//set 1000 random items, then read 10000 items.
18//since they are random, there will be misses as well as hits
19console.log('GET', run(100000, function (lru, n) {
20 lru.get(~~(Math.random()*1000))
21// lru.set(n, Math.random())
22}, function () {
23 var lru = LRU(1000)
24 for(var i = 0; i ++ ; i < 1000)
25 lru.set(~~(Math.random()*1000), Math.random())
26 return lru
27}))
28
29//set 100000 random values into LRU for 1000 values.
30//this means 99/100 should be evictions
31console.log('SET', run(100000, function (lru, n) {
32 lru.set(~~(Math.random()*100000), Math.random())
33}, function () {
34 return LRU(1000)
35}))
36
37
38
39
40
41
42
43
44
45
46
47
48

Built with git-ssb-web