You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					48 lines
				
				994 B
			
		
		
			
		
	
	
					48 lines
				
				994 B
			| 
											3 years ago
										 | var Stats = require('statistics/mutate') | ||
|  | var LRU = require('./') | ||
|  | 
 | ||
|  | //simple benchmarks, and measure standard deviation
 | ||
|  | 
 | ||
|  | function run (N, op, init) { | ||
|  |   var stats = null, value | ||
|  |   for(var j = 0; j < 100; j++) { | ||
|  |     if(init) value = init(j) | ||
|  |     var start = Date.now() | ||
|  |     for(var i = 0; i < N; i++) op(value, i) | ||
|  |     stats = Stats(stats, N/((Date.now() - start))) | ||
|  |   } | ||
|  |   return stats | ||
|  | } | ||
|  | 
 | ||
|  | //set 1000 random items, then read 10000 items.
 | ||
|  | //since they are random, there will be misses as well as hits
 | ||
|  | console.log('GET', run(100000, function (lru, n) { | ||
|  |   lru.get(~~(Math.random()*1000)) | ||
|  | //  lru.set(n, Math.random())
 | ||
|  | }, function () { | ||
|  |   var lru = LRU(1000) | ||
|  |   for(var i = 0; i ++ ; i < 1000) | ||
|  |     lru.set(~~(Math.random()*1000), Math.random()) | ||
|  |   return lru | ||
|  | })) | ||
|  | 
 | ||
|  | //set 100000 random values into LRU for 1000 values.
 | ||
|  | //this means 99/100 should be evictions
 | ||
|  | console.log('SET', run(100000, function (lru, n) { | ||
|  |   lru.set(~~(Math.random()*100000), Math.random()) | ||
|  | }, function () { | ||
|  |   return LRU(1000) | ||
|  | })) | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 |