forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: nodejs#18320 Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
10 changed files
with
130 additions
and
106 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
noAssert: ['false', 'true'], | ||
type: ['Double', 'Float'], | ||
endian: ['BE', 'LE'], | ||
value: ['zero', 'big', 'small', 'inf', 'nan'], | ||
millions: [1] | ||
}); | ||
|
||
function main({ noAssert, millions, type, endian, value }) { | ||
noAssert = noAssert === 'true'; | ||
type = type || 'Double'; | ||
const buff = Buffer.alloc(8); | ||
const fn = `read${type}${endian}`; | ||
const values = { | ||
Double: { | ||
zero: 0, | ||
big: 2 ** 1023, | ||
small: 2 ** -1074, | ||
inf: Infinity, | ||
nan: NaN, | ||
}, | ||
Float: { | ||
zero: 0, | ||
big: 2 ** 127, | ||
small: 2 ** -149, | ||
inf: Infinity, | ||
nan: NaN, | ||
}, | ||
}; | ||
|
||
buff[`write${type}${endian}`](values[type][value], 0, noAssert); | ||
|
||
bench.start(); | ||
for (var i = 0; i !== millions * 1e6; i++) { | ||
buff[fn](0, noAssert); | ||
} | ||
bench.end(millions); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const types = [ | ||
'IntBE', | ||
'IntLE', | ||
'UIntBE', | ||
'UIntLE' | ||
]; | ||
|
||
const bench = common.createBenchmark(main, { | ||
noAssert: ['false', 'true'], | ||
buffer: ['fast', 'slow'], | ||
type: types, | ||
millions: [1], | ||
byteLength: [1, 2, 4, 6] | ||
}); | ||
|
||
function main({ millions, noAssert, buf, type, byteLength }) { | ||
noAssert = noAssert === 'true'; | ||
type = type || 'UInt8'; | ||
const clazz = buf === 'fast' ? Buffer : require('buffer').SlowBuffer; | ||
const buff = new clazz(8); | ||
const fn = `read${type}`; | ||
|
||
buff.writeDoubleLE(0, 0, noAssert); | ||
bench.start(); | ||
for (var i = 0; i !== millions * 1e6; i++) { | ||
buff[fn](0, byteLength, noAssert); | ||
} | ||
bench.end(millions); | ||
} |
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
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
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