Last active
August 29, 2015 14:11
-
-
Save rootslab/01c7a3d4bca97c85d078 to your computer and use it in GitHub Desktop.
io.js PR#169 https://github.com/iojs/io.js/pull/169
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
Buffer.prototype.readUInt24LE = function(offset, noAssert) { | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkOffset(offset, 3, this.length); | |
return ((this[offset]) | | |
(this[offset + 1] << 8) | | |
(this[offset + 2] << 16)); | |
}; | |
Buffer.prototype.readUInt24BE = function(offset, noAssert) { | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkOffset(offset, 3, this.length); | |
return ((this[offset] << 16) | | |
(this[offset + 1] << 8) | | |
this[offset + 2]); | |
}; | |
Buffer.prototype.readInt24LE = function(offset, noAssert) { | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkOffset(offset, 3, this.length); | |
return (this[offset]) | | |
(this[offset + 1] << 8) | | |
(this[offset + 2] << 16); | |
}; | |
Buffer.prototype.readInt24BE = function(offset, noAssert) { | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkOffset(offset, 3, this.length); | |
return (this[offset] << 16) | | |
(this[offset + 1] << 8) | | |
(this[offset + 2]); | |
}; | |
Buffer.prototype.writeUInt24LE = function(value, offset, noAssert) { | |
value = +value; | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkInt(this, value, offset, 3, 0xffffff, 0); | |
this[offset + 2] = (value >>> 16); | |
this[offset + 1] = (value >>> 8); | |
this[offset] = value; | |
return offset + 3; | |
}; | |
Buffer.prototype.writeUInt24BE = function(value, offset, noAssert) { | |
value = +value; | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkInt(this, value, offset, 3, 0xffffff, 0); | |
this[offset] = (value >>> 16); | |
this[offset + 1] = (value >>> 8); | |
this[offset + 2] = value; | |
return offset + 3; | |
}; | |
Buffer.prototype.writeInt24LE = function(value, offset, noAssert) { | |
value = +value; | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkInt(this, value, offset, 3, 0x7fffff, -0x800000); | |
this[offset] = value; | |
this[offset + 1] = (value >>> 8); | |
this[offset + 2] = (value >>> 16); | |
return offset + 3; | |
}; | |
Buffer.prototype.writeInt24BE = function(value, offset, noAssert) { | |
value = +value; | |
offset = offset >>> 0; | |
if (!noAssert) | |
checkInt(this, value, offset, 3, 0x7fffff, -0x800000); | |
this[offset] = (value >>> 16); | |
this[offset + 1] = (value >>> 8); | |
this[offset + 2] = value; | |
return offset + 3; | |
}; |
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 log = console.log | |
, Kombo = require( '../' ) | |
, test = function ( mbytes ) { | |
var mb = Math.max( mbytes, 1 ) | |
, b = new Buffer( mb * 1024 * 1024 ) | |
, stime = -1 | |
, etime= -1 | |
, i = 0 | |
; | |
log( '\nfilling test buffer (%d MB)..', mb ); | |
for ( ; i < b.length; ++i ) b[ i ] = i; | |
stime = Date.now(); | |
for ( i = 0; i < b.length - 3; i+= 3 ) b.readUIntBE( i, 3 ); | |
etime = Date.now(); | |
log( '- readUIntBE: %d s', ( etime - stime ) / 1000 ); | |
stime = Date.now(); | |
for ( i = 0; i < b.length - 3; i+= 3 ) b.readUInt24BE( i ); | |
etime = Date.now(); | |
log( '- readUInt24BE: %d s', ( etime - stime ) / 1000 ) | |
stime = Date.now(); | |
for ( i = 0; i < b.length - 3; i+= 3 ) b.writeUIntBE( 0xffffff, i, 3 ); | |
etime = Date.now(); | |
log( '- writeUIntBE: %d s', ( etime - stime ) / 1000 ); | |
stime = Date.now(); | |
for ( i = 0; i < b.length - 3; i+= 3 ) b.writeUInt24BE( 0xffffff, i ); | |
etime = Date.now(); | |
log( '- writeUInt24BE: %d s', ( etime - stime ) / 1000 ); | |
}; | |
test( 1 ); | |
test( 8 ); | |
test( 16 ); | |
test( 32 ); | |
test( 64 ); | |
test( 128 ); | |
log(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output results:
filling test buffer (1 MB)..
filling test buffer (8 MB)..
filling test buffer (16 MB)..
filling test buffer (32 MB)..
filling test buffer (64 MB)..
filling test buffer (128 MB)..