Skip to content

Instantly share code, notes, and snippets.

@nponeccop
Last active December 12, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nponeccop/4703620 to your computer and use it in GitHub Desktop.
Save nponeccop/4703620 to your computer and use it in GitHub Desktop.
File writing benchmark
#include <windows.h>
HANDLE f;
void my_open(char *fileName)
{
f = CreateFile(
fileName,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL
);
}
void my_write(char *buf, size_t size)
{
DWORD written;
WriteFile(f, buf, size, &written, NULL);
}
void my_close()
{
CloseHandle(f);
}
import Data.ByteString as BL
import System.IO
import Control.Monad
import Control.Concurrent
main = do
let buf = BL.replicate (1024 * 100) 48
h <- openFile "t:\\foo" WriteMode
threadDelay $ 10 * 1000000
forM_ [1..200000] $ const $ BL.hPutStr h buf
hClose h
var b = ''
for (var i = 0; i < 1024 * 100; i++)
{
b += '0'
}
var buf = new Buffer(b)
var m = require('./' + process.argv[2])
m.open("t:\\foo", {
open : setTimeout.bind(null, foo, 10000)
, drain : foo
})
var writes = 0
function foo()
{
do { } while (writes++ < 200000 && m.write(buf))
}
#include <windows.h>
#include <stdio.h>
void my_open(char *);
void my_write(char*, size_t);
void my_close();
int main(void)
{
my_open("T:\\foo");
char * buf = new char[1024 * 100];
for (int i = 0; i < 1024 * 100; i++)
{
buf[i] = i;
}
Sleep(10000);
for (int i = 0; i < 200000; i++)
{
my_write(buf, 1024 * 100);
}
my_close();
return 0;
}
var buf = ''
for (var i = 0; i < 1024 * 100; i++)
{
buf += '0'
}
var m = require('./' + process.argv[2])
m.open("t:\\foo", {
open : setTimeout.bind(null, foo, 10000)
, drain : foo
})
var writes = 0
function foo()
{
do { } while (writes++ < 200000 && m.write(buf))
}
var fs = require('fs')
var f
exports.open = function (fileName, cb)
{
f = fs.createWriteStream(fileName)
exports.write = f.write.bind(f)
f.on('drain', cb.drain)
f.on('open', cb.open)
}
use IO::File;
my $f = new IO::File "t:\\foo", "w";
my $buf = '';
for (my $i = 0; $i < 1024 * 100; $i++)
{
$buf .= "a"
}
sleep 10;
for (my $i = 0; i < 200000; $i++)
{
$f->write($buf);
}
use IO::File;
my $f = new IO::File "t:\\foo", "w";
my $buf = "a" x 1024_00;
sleep 10;
for (my $i = 0; i < 200000; $i++)
{
$f->syswrite($buf, 1024_00);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment