Created
March 29, 2012 13:13
-
-
Save seriousManual/2237364 to your computer and use it in GitHub Desktop.
replicating very high cpu usage when not doing any calculation at all
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
var data = [] | |
,number = 5000 | |
,numberElements = 130 | |
,numberQueries = 15; | |
for( var i = 0; i < number; i++ ) { | |
data[ i ] = {}; | |
for( var x = 0; x < numberElements; x++ ) { | |
data[ i ][ createRandomString( 10 ) ] = createRandomString( 20 ); | |
} | |
} | |
console.log( 'finished' ); | |
process.stdin.resume(); | |
process.stdin.on( 'data', query ); | |
function query( ) { | |
var result = [] | |
,start = new Date().getTime(); | |
for ( var i = 0; i < data.length; i++ ) { | |
for( var numberQuery = 0; numberQuery < numberQueries; numberQuery++ ) { | |
var str = createRandomString( 10 ); | |
if ( data[ i ][ str ] ) { | |
result.push( str ); | |
} | |
} | |
} | |
console.log( new Date().getTime() - start ); | |
console.log( result ); | |
} | |
function createRandomString( length ) { | |
var res = ''; | |
var src = 'abcdefghijklmnopqrstuvwxyz01234567890'; | |
for( var i = 0; i < length; i++ ) { | |
res += src.charAt( Math.floor( Math.random() * src.length ) ); | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment