summaryrefslogtreecommitdiff
path: root/benchmark/buffers
diff options
context:
space:
mode:
authorNick Apperson <apperson@gmail.com>2014-03-25 09:51:13 -0500
committerTrevor Norris <trev.norris@gmail.com>2014-04-01 17:31:28 -0700
commitd4fcb23e38e74d21e04b3a17d10e52949b630ec0 (patch)
treede43d5bf27c9892e374440dc23432faf84173f4b /benchmark/buffers
parentc7214fe355596543d92d7c10b38d78ca65b4abfe (diff)
downloadandroid-node-v8-d4fcb23e38e74d21e04b3a17d10e52949b630ec0.tar.gz
android-node-v8-d4fcb23e38e74d21e04b3a17d10e52949b630ec0.tar.bz2
android-node-v8-d4fcb23e38e74d21e04b3a17d10e52949b630ec0.zip
buffer: improve {read,write}{U}Int* methods
Increase the performance and simplify the logic of Buffer#write{U}Int* and Buffer#read{U}Int* methods by placing the byte manipulation code directly inline. Also improve the speed of buffer-write benchmarks by creating a new call directly to each method by using Function() instead of calling by buff[fn]. Signed-off-by: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'benchmark/buffers')
-rw-r--r--benchmark/buffers/buffer-read.js9
-rw-r--r--benchmark/buffers/buffer-write.js24
2 files changed, 21 insertions, 12 deletions
diff --git a/benchmark/buffers/buffer-read.js b/benchmark/buffers/buffer-read.js
index fccd99dcd2..92138bccef 100644
--- a/benchmark/buffers/buffer-read.js
+++ b/benchmark/buffers/buffer-read.js
@@ -20,9 +20,12 @@ function main(conf) {
var fn = 'read' + conf.type;
buff.writeDoubleLE(0, 0, noAssert);
+ var testFunction = new Function('buff', [
+ "for (var i = 0; i !== " + len + "; i++) {",
+ " buff." + fn + "(0, " + JSON.stringify(noAssert) + ");",
+ "}"
+ ].join("\n"));
bench.start();
- for (var i = 0; i < len; i++) {
- buff[fn](0, noAssert);
- }
+ testFunction(buff);
bench.end(len / 1e6);
}
diff --git a/benchmark/buffers/buffer-write.js b/benchmark/buffers/buffer-write.js
index 4dbfcb6096..2a2a0e37e3 100644
--- a/benchmark/buffers/buffer-write.js
+++ b/benchmark/buffers/buffer-write.js
@@ -15,9 +15,9 @@ var bench = common.createBenchmark(main, {
const INT8 = 0x7f;
const INT16 = 0x7fff;
const INT32 = 0x7fffffff;
-const UINT8 = INT8 * 2;
-const UINT16 = INT16 * 2;
-const UINT32 = INT32 * 2;
+const UINT8 = (INT8 * 2) + 1;
+const UINT16 = (INT16 * 2) + 1;
+const UINT32 = INT32;
var mod = {
writeInt8: INT8,
@@ -47,17 +47,23 @@ function main(conf) {
function benchInt(buff, fn, len, noAssert) {
var m = mod[fn];
+ var testFunction = new Function('buff', [
+ "for (var i = 0; i !== " + len + "; i++) {",
+ " buff." + fn + "(i & " + m + ", 0, " + JSON.stringify(noAssert) + ");",
+ "}"
+ ].join("\n"));
bench.start();
- for (var i = 0; i < len; i++) {
- buff[fn](i % m, 0, noAssert);
- }
+ testFunction(buff);
bench.end(len / 1e6);
}
function benchFloat(buff, fn, len, noAssert) {
+ var testFunction = new Function('buff', [
+ "for (var i = 0; i !== " + len + "; i++) {",
+ " buff." + fn + "(i, 0, " + JSON.stringify(noAssert) + ");",
+ "}"
+ ].join("\n"));
bench.start();
- for (var i = 0; i < len; i++) {
- buff[fn](i * 0.1, 0, noAssert);
- }
+ testFunction(buff);
bench.end(len / 1e6);
}