Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix timing on I/O benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 25, 2010
1 parent 3fc9192 commit 353e256
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
6 changes: 4 additions & 2 deletions benchmark/function_call/bench.js
@@ -1,12 +1,14 @@
var binding = require('./build/default/binding');

c = 0

function js() {
return (new Date()).getTime();
return c++; //(new Date()).getTime();
}

var cxx = binding.hello;

var i, N = 10000000;
var i, N = 100000000;

console.log(js());
console.log(cxx());
Expand Down
6 changes: 4 additions & 2 deletions benchmark/function_call/binding.cc
Expand Up @@ -4,10 +4,12 @@

using namespace v8;

static int c = 0;

static Handle<Value> Hello(const Arguments& args) {
HandleScope scope;
time_t tv = time(NULL);
return scope.Close(Integer::New(tv));
//time_t tv = time(NULL);
return scope.Close(Integer::New(c++));
}

extern "C" void init (Handle<Object> target) {
Expand Down
25 changes: 14 additions & 11 deletions benchmark/io.c
Expand Up @@ -5,13 +5,15 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

int tsize = 1000 * 1048576;
const char *path = "/tmp/wt.dat";

int c = 0;

char* bufit(size_t l)
{
Expand All @@ -24,7 +26,7 @@ void writetest(int size, size_t bsize)
{
int i;
char *buf = bufit(bsize);
clock_t start, end;
struct timeval start, end;
double elapsed;
double mbps;

Expand All @@ -34,9 +36,10 @@ void writetest(int size, size_t bsize)
exit(254);
}

start = clock();
assert(0 == gettimeofday(&start, NULL));
for (i = 0; i < size; i += bsize) {
int rv = write(fd, buf, bsize);
if (c++ % 2000 == 0) fprintf(stderr, ".");
if (rv < 0) {
perror("write failed");
exit(254);
Expand All @@ -48,10 +51,10 @@ void writetest(int size, size_t bsize)
fsync(fd);
#endif
close(fd);
end = clock();
elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
assert(0 == gettimeofday(&end, NULL));
elapsed = (end.tv_sec - start.tv_sec) + ((double)(end.tv_usec - start.tv_usec))/100000.;
mbps = ((tsize/elapsed)) / 1048576;
fprintf(stderr, "Wrote %d bytes in %03fs using %d byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps);
fprintf(stderr, "\nWrote %d bytes in %03fs using %ld byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps);

free(buf);
}
Expand All @@ -60,7 +63,7 @@ void readtest(int size, size_t bsize)
{
int i;
char *buf = bufit(bsize);
clock_t start, end;
struct timeval start, end;
double elapsed;
double mbps;

Expand All @@ -70,7 +73,7 @@ void readtest(int size, size_t bsize)
exit(254);
}

start = clock();
assert(0 == gettimeofday(&start, NULL));
for (i = 0; i < size; i += bsize) {
int rv = read(fd, buf, bsize);
if (rv < 0) {
Expand All @@ -79,10 +82,10 @@ void readtest(int size, size_t bsize)
}
}
close(fd);
end = clock();
elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
assert(0 == gettimeofday(&end, NULL));
elapsed = (end.tv_sec - start.tv_sec) + ((double)(end.tv_usec - start.tv_usec))/100000.;
mbps = ((tsize/elapsed)) / 1048576;
fprintf(stderr, "Read %d bytes in %03fs using %d byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps);
fprintf(stderr, "Read %d bytes in %03fs using %ld byte buffers: %03fmB/s\n", size, elapsed, bsize, mbps);

free(buf);
}
Expand Down
4 changes: 4 additions & 0 deletions benchmark/io.js
@@ -1,4 +1,5 @@
var fs = require('fs');
var sys = require('sys');
var Buffer = require('buffer').Buffer;

var path = "/tmp/wt.dat";
Expand All @@ -21,6 +22,8 @@ function once(emitter, name, cb) {
emitter.addListener(name, incb);
}

c = 0

function writetest(size, bsize) {
var s = fs.createWriteStream(path, {'flags': 'w', 'mode': 0644});
var remaining = size;
Expand All @@ -40,6 +43,7 @@ function writetest(size, bsize) {

s.on('drain', function () {
dowrite();
if (c++ % 2000 == 0) sys.print(".");
});

dowrite();
Expand Down

0 comments on commit 353e256

Please sign in to comment.