FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node/benchmark/io.js at master · objcode/node · GitHub
objcode
/
node
Public
forked from
nodejs/node-v0.x-archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node
/
benchmark
/
io.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
105 lines (89 loc) · 2.24 KB
Breadcrumbs
node
/
benchmark
/
io.js
Copy path
File metadata and controls
105 lines (89 loc) · 2.24 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
104
105
var
fs
=
require
(
'fs'
)
;
var
Buffer
=
require
(
'buffer'
)
.
Buffer
;
var
path
=
"/tmp/wt.dat"
;
var
tsize
=
1000
*
1048576
;
var
bsizes
=
[
1024
,
4096
,
8192
,
16384
,
32768
,
65536
]
;
function
bufit
(
size
)
{
var
buf
=
new
Buffer
(
size
)
;
for
(
var
i
=
0
;
i
<
buf
.
length
;
i
+=
1
)
{
buf
[
i
]
=
33
;
}
return
buf
;
}
function
once
(
emitter
,
name
,
cb
)
{
function
incb
(
)
{
cb
.
apply
(
undefined
,
arguments
)
;
emitter
.
removeListener
(
name
,
incb
)
;
}
emitter
.
addListener
(
name
,
incb
)
;
}
function
writetest
(
size
,
bsize
)
{
var
s
=
fs
.
createWriteStream
(
path
,
{
'flags'
:
'w'
,
'mode'
:
0644
}
)
;
var
remaining
=
size
;
var
buf
=
bufit
(
bsize
)
;
function
dowrite
(
)
{
var
rv
=
s
.
write
(
buf
)
;
remaining
-=
buf
.
length
;
if
(
remaining
>
0
)
{
//if (remaining % 90000 == 0) console.error("remaining: %d", remaining);
//process.nextTick(dowrite);
}
else
{
s
.
emit
(
'done'
)
s
.
end
(
)
;
}
}
s
.
on
(
'drain'
,
function
(
)
{
dowrite
(
)
;
}
)
;
dowrite
(
)
;
return
s
;
}
function
readtest
(
size
,
bsize
)
{
var
s
=
fs
.
createReadStream
(
path
,
{
'flags'
:
'r'
,
'encoding'
:
'binary'
,
'mode'
:
0644
,
'bufferSize'
:
bsize
}
)
;
s
.
addListener
(
"data"
,
function
(
chunk
)
{
// got a chunk...
}
)
;
return
s
;
}
function
wt
(
tsize
,
bsize
,
done
)
{
var
start
=
Date
.
now
(
)
;
s
=
writetest
(
tsize
,
bsizes
[
0
]
)
;
s
.
addListener
(
'close'
,
function
(
)
{
var
end
=
Date
.
now
(
)
;
var
diff
=
end
-
start
;
console
.
log
(
'Wrote '
+
tsize
+
' bytes in '
+
diff
/
1000
+
's using '
+
bsize
+
' byte buffers: '
+
(
(
tsize
/
(
diff
/
1000
)
)
/
1048576
)
+
' mB/s'
)
;
done
(
)
;
}
)
;
}
function
rt
(
tsize
,
bsize
,
done
)
{
var
start
=
Date
.
now
(
)
;
s
=
readtest
(
tsize
,
bsizes
[
0
]
)
;
s
.
addListener
(
'close'
,
function
(
)
{
var
end
=
Date
.
now
(
)
;
var
diff
=
end
-
start
;
console
.
log
(
'Read '
+
tsize
+
' bytes in '
+
diff
/
1000
+
's using '
+
bsize
+
' byte buffers: '
+
(
(
tsize
/
(
diff
/
1000
)
)
/
1048576
)
+
' mB/s'
)
;
done
(
)
;
}
)
;
}
var
bs
=
0
;
function
nextwt
(
)
{
if
(
bsizes
.
length
<=
bs
)
{
bs
=
0
;
nextrt
(
)
;
return
;
}
wt
(
tsize
,
bsizes
[
bs
]
,
nextwt
)
;
bs
+=
1
;
}
function
nextrt
(
)
{
if
(
bsizes
.
length
<=
bs
)
{
fs
.
unlink
(
path
,
function
(
err
)
{
if
(
err
)
throw
err
;
console
.
log
(
'All done!'
)
;
}
)
;
return
;
}
rt
(
tsize
,
bsizes
[
bs
]
,
nextrt
)
;
bs
+=
1
;
}
nextwt
(
)
;
Back
|
FazBrowse Home
|
New Git URL