Skip to content

Instantly share code, notes, and snippets.

@seriousManual
Created March 29, 2012 13:13
Show Gist options
  • Save seriousManual/2237364 to your computer and use it in GitHub Desktop.
Save seriousManual/2237364 to your computer and use it in GitHub Desktop.
replicating very high cpu usage when not doing any calculation at all
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