Skip to content

Commit

Permalink
little correction to crook benchmark..
Browse files Browse the repository at this point in the history
On branch master
Changes to be committed:
modified:   bench/best-magic-data-rate.js
  • Loading branch information
rootslab committed Apr 20, 2013
1 parent 653897c commit dd0a34b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bench/best-magic-data-rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var log = console.log,
dlength = 700,
stime = 0,
boundary = new Buffer( 57 ),

// build test data to parse
data = ( function () {
var test = new Buffer( dlength * 1024 * 1024),
t = 0,
Expand All @@ -14,7 +14,7 @@ var log = console.log,
log( '- test buffer created..' );
return test;
} )(),

// crook parse method
magicParse = function ( pattern, data ) {
var i = 0,
dlen = data.length,
Expand All @@ -23,9 +23,11 @@ var log = console.log,
pchar = pattern[ plen - 1 ];
log( '- now parsing test buffer with magic algorithm..' );
for( stime = Date.now(); i < dlen; i += plen ) {
// access data and compare current byte with the last byte of pattern,
// then skip plen bytes, no other comparison.
// ( best performance O(m/n) )
/*
* access data and compare current byte with the last byte of pattern,
* then skip plen bytes, no other comparison.
* best performance O(n/m)
*/
if( pchar === data[ i ] ) {
// ..
}
Expand Down

0 comments on commit dd0a34b

Please sign in to comment.