joyent/node — Issue #2020: benchmark / io.c & io.js  were meaningless and misleading...
Author: windyrobin
Created: 2011-11-05 09:47:04+00:00
State: open

@ry
when run the test files and compare the result , io.js is much slower
result is like below :

```js
io.c
Wrote 1048576000 bytes in 12.767330s using 1024 byte buffers: 78.324912mB/s
Wrote 1048576000 bytes in 9.445630s using 4096 byte buffers: 105.869063mB/s
Wrote 1048576000 bytes in 15.407120s using 8192 byte buffers: 64.905057mB/s
Wrote 1048576000 bytes in 15.047700s using 16384 byte buffers: 66.455339mB/s
Wrote 1048576000 bytes in 3.274550s using 32768 byte buffers: 305.385473mB/s
Wrote 1048576000 bytes in 16.351850s using 65536 byte buffers: 61.155160mB/s
Read 1048576000 bytes in -1.917090s using 1024 byte buffers: -521.623920mB/s
Read 1048576000 bytes in 5.439520s using 4096 byte buffers: 183.839751mB/s
Read 1048576000 bytes in -5.343230s using 8192 byte buffers: -187.152715mB/s
Read 1048576000 bytes in 2.888460s using 16384 byte buffers: 346.205244mB/s
Read 1048576000 bytes in 2.534980s using 32768 byte buffers: 394.480430mB/s
Read 1048576000 bytes in 2.323350s using 65536 byte buffers: 430.412981mB/s
```

```js
io.js
Wrote 1048576000 bytes in 45.432s using 1024 byte buffers: 22.01091741503786 mB/s
Wrote 1048576000 bytes in 45.944s using 4096 byte buffers: 21.765627720703463 mB/s
Wrote 1048576000 bytes in 45.003s using 8192 byte buffers: 22.220740839499587 mB/s
Wrote 1048576000 bytes in 46.339s using 16384 byte buffers: 21.580094520814 mB/s
Wrote 1048576000 bytes in 46.387s using 32768 byte buffers: 21.557764028714942 mB/s
Wrote 1048576000 bytes in 44.78s using 65536 byte buffers: 22.331397945511387 mB/s
Read 1048576000 bytes in 32.78s using 1024 byte buffers: 30.50640634533252 mB/s
Read 1048576000 bytes in 32.638s using 4096 byte buffers: 30.639132299773273 mB/s
Read 1048576000 bytes in 33.12s using 8192 byte buffers: 30.193236714975846 mB/s
Read 1048576000 bytes in 33.344s using 16384 byte buffers: 29.990403071017273 mB/s
Read 1048576000 bytes in 32.841s using 32768 byte buffers: 30.449742699674186 mB/s
Read 1048576000 bytes in 32.701s using 65536 byte buffers: 30.580104583957677 mB/s
```

but there are two factors which deeply affect the result :

- io.c uses 'fdatasync' which io.js doesn't
- io.c uses 'malloc' which io.js use 'new Buffer'

so I just comment 'fdatasync' in io.c and rewrite the bufblt:

```c
char buff[1024*128];
char* bufit(size_t l)
{
return buff;
char *p = malloc(l);
memset(p, '!', l);
return p;
}
```
and also comment the line 'free buf'

in io.js :

```js
var ibuf = new Buffer(128*1024);
function bufit(size) {
return ibuf;
var buf = new Buffer(size);
for (var i = 0; i