About File.rawWrite
bearophile
bearophileHUGS at lycos.com
Tue Nov 29 04:57:19 PST 2011
This D2 program runs in about 5.13 seconds on my PC:
import std.stdio;
void main() {
auto f = File("bytes_test.dat", "wb");
ubyte[3] RGB;
foreach (_; 0 .. 1_000_000)
f.rawWrite(RGB);
}
While this C program runs in about 0.14 seconds:
#include <stdio.h>
int main() {
FILE *f = fopen("bytes_test.dat", "wb");
unsigned char RGB[3] = {0};
int i;
for (i = 0; i < 1000000; i++)
fwrite(RGB, 1, 3, f);
return 0;
}
Is my D2 program wrong, or is File.rawWrite in need of some improvements?
(Writing 3 bytes at a time is not efficient, but the C code shows that the runtime is acceptable for me for small files).
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list