Last active
December 12, 2015 02:59
-
-
Save nponeccop/4703620 to your computer and use it in GitHub Desktop.
File writing benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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