From 3d8532f851f2f7a2f8380e717281eaa08b02fb35 Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sun, 3 Jun 2018 20:30:46 +0300 Subject: buffer: add {read|write}Big[U]Int64{BE|LE} methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/19691 Reviewed-By: Ben Noordhuis Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Joyee Cheung Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Tobias Nießen Reviewed-By: Matteo Collina --- benchmark/buffers/buffer-read.js | 4 ++++ benchmark/buffers/buffer-write.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'benchmark') diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js index 38a9a847b3..06e2c6c70e 100644 --- a/benchmark/buffers/buffer-read.js +++ b/benchmark/buffers/buffer-read.js @@ -2,6 +2,10 @@ const common = require('../common.js'); const types = [ + 'BigUInt64LE', + 'BigUInt64BE', + 'BigInt64LE', + 'BigInt64BE', 'UInt8', 'UInt16LE', 'UInt16BE', diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js index 33d33a63fc..be5a6adc8e 100644 --- a/benchmark/buffers/buffer-write.js +++ b/benchmark/buffers/buffer-write.js @@ -2,6 +2,10 @@ const common = require('../common.js'); const types = [ + 'BigUInt64LE', + 'BigUInt64BE', + 'BigInt64LE', + 'BigInt64BE', 'UInt8', 'UInt16LE', 'UInt16BE', @@ -32,11 +36,17 @@ const INT8 = 0x7f; const INT16 = 0x7fff; const INT32 = 0x7fffffff; const INT48 = 0x7fffffffffff; +const INT64 = 0x7fffffffffffffffn; const UINT8 = 0xff; const UINT16 = 0xffff; const UINT32 = 0xffffffff; +const UINT64 = 0xffffffffffffffffn; const mod = { + writeBigInt64BE: INT64, + writeBigInt64LE: INT64, + writeBigUInt64BE: UINT64, + writeBigUInt64LE: UINT64, writeInt8: INT8, writeInt16BE: INT16, writeInt16LE: INT16, @@ -67,12 +77,23 @@ function main({ n, buf, type }) { if (!/\d/.test(fn)) benchSpecialInt(buff, fn, n); + else if (/BigU?Int/.test(fn)) + benchBigInt(buff, fn, BigInt(n)); else if (/Int/.test(fn)) benchInt(buff, fn, n); else benchFloat(buff, fn, n); } +function benchBigInt(buff, fn, n) { + const m = mod[fn]; + bench.start(); + for (var i = 0n; i !== n; i++) { + buff[fn](i & m, 0); + } + bench.end(Number(n)); +} + function benchInt(buff, fn, n) { const m = mod[fn]; bench.start(); -- cgit v1.2.3