diff --git a/benchmark/io.c b/benchmark/io.c new file mode 100644 index 0000000000..068d50ee1b --- /dev/null +++ b/benchmark/io.c @@ -0,0 +1,107 @@ +/** + * gcc -o iotest io.c + */ + +#include +#include +#include +#include +#include +#include + +int tsize = 1000 * 1048576; +const char *path = "/tmp/wt.dat"; + + +char* bufit(size_t l) +{ + char *p = malloc(l); + memset(p, '!', l); + return p; +} + +void writetest(int size, size_t bsize) +{ + int i; + char *buf = bufit(bsize); + clock_t start, end; + double elapsed; + double mbps; + + int fd = open(path, O_CREAT|O_WRONLY, 0644); + if (fd < 0) { + perror("open failed"); + exit(254); + } + + start = clock(); + for (i = 0; i < size; i += bsize) { + int rv = write(fd, buf, bsize); + if (rv < 0) { + perror("write failed"); + exit(254); + } + } +#ifdef __linux__ + fdatasync(fd); +#else + fsync(fd); +#endif + close(fd); + end = clock(); + elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; + mbps = ((tsize/elapsed)) / 1048576; + fprintf(stderr, "Wrote %d bytes in %03fs using %d byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps); + + free(buf); +} + +void readtest(int size, size_t bsize) +{ + int i; + char *buf = bufit(bsize); + clock_t start, end; + double elapsed; + double mbps; + + int fd = open(path, O_RDONLY, 0644); + if (fd < 0) { + perror("open failed"); + exit(254); + } + + start = clock(); + for (i = 0; i < size; i += bsize) { + int rv = read(fd, buf, bsize); + if (rv < 0) { + perror("write failed"); + exit(254); + } + } + close(fd); + end = clock(); + elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; + mbps = ((tsize/elapsed)) / 1048576; + fprintf(stderr, "Read %d bytes in %03fs using %d byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps); + + free(buf); +} + +void cleanup() { + unlink(path); +} + +int main() +{ + int i; + int bsizes[] = {1024, 4096, 8192, 16384, 32768, 65536, 0}; + + for (i = 0; bsizes[i] != 0; i++) { + writetest(tsize, bsizes[i]); + } + for (i = 0; bsizes[i] != 0; i++) { + readtest(tsize, bsizes[i]); + } + atexit(cleanup); + return 0; +} diff --git a/benchmark/io.js b/benchmark/io.js new file mode 100644 index 0000000000..060f3cd2a3 --- /dev/null +++ b/benchmark/io.js @@ -0,0 +1,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 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();