This repository was archived by the owner on Apr 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Expand file tree
/
Copy pathbuffer_write.js
More file actions
103 lines (85 loc) · 2.1 KB
/
buffer_write.js
File metadata and controls
103 lines (85 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const LEN = 1e7;
const INT8 = 0x7f;
const INT16 = 0x7fff;
const INT32 = 0x7fffffff;
const UINT8 = INT8 * 2;
const UINT16 = INT16 * 2;
const UINT32 = INT32 * 2;
const noAssert = process.argv[3] == 'true' ? true
: process.argv[3] == 'false' ? false
: undefined;
var timer = require('./_bench_timer');
var buff = (process.argv[2] == 'slow') ?
(new require('buffer').SlowBuffer(8)) :
(new Buffer(8));
var i;
timer('writeUInt8', function() {
for (i = 0; i < LEN; i++) {
buff.writeUInt8(i % UINT8, 0, noAssert);
}
});
timer('writeUInt16LE', function() {
for (i = 0; i < LEN; i++) {
buff.writeUInt16LE(i % UINT16, 0, noAssert);
}
});
timer('writeUInt16BE', function() {
for (i = 0; i < LEN; i++) {
buff.writeUInt16BE(i % UINT16, 0, noAssert);
}
});
timer('writeUInt32LE', function() {
for (i = 0; i < LEN; i++) {
buff.writeUInt32LE(i % UINT32, 0, noAssert);
}
});
timer('writeUInt32BE', function() {
for (i = 0; i < LEN; i++) {
buff.writeUInt32BE(i % UINT32, 0, noAssert);
}
});
timer('writeInt8', function() {
for (i = 0; i < LEN; i++) {
buff.writeInt8(i % INT8, 0, noAssert);
}
});
timer('writeInt16LE', function() {
for (i = 0; i < LEN; i++) {
buff.writeInt16LE(i % INT16, 0, noAssert);
}
});
timer('writeInt16BE', function() {
for (i = 0; i < LEN; i++) {
buff.writeInt16BE(i % INT16, 0, noAssert);
}
});
timer('writeInt32LE', function() {
for (i = 0; i < LEN; i++) {
buff.writeInt32LE(i % INT32, 0, noAssert);
}
});
timer('writeInt32BE', function() {
for (i = 0; i < LEN; i++) {
buff.writeInt32BE(i % INT32, 0, noAssert);
}
});
timer('writeFloatLE', function() {
for (i = 0; i < LEN; i++) {
buff.writeFloatLE(i * 0.1, 0, noAssert);
}
});
timer('writeFloatBE', function() {
for (i = 0; i < LEN; i++) {
buff.writeFloatBE(i * 0.1, 0, noAssert);
}
});
timer('writeDoubleLE', function() {
for (i = 0; i < LEN; i++) {
buff.writeDoubleLE(i * 0.1, 0, noAssert);
}
});
timer('writeDoubleBE', function() {
for (i = 0; i < LEN; i++) {
buff.writeDoubleBE(i * 0.1, 0, noAssert);
}
});