some regex vs std.ascii vs handcode times

Juan Manuel Cabo juanmanuel.cabo at gmail.com
Tue Mar 20 23:55:19 PDT 2012


On Wednesday, 21 March 2012 at 05:49:29 UTC, Juan Manuel Cabo 
wrote:
> On Monday, 19 March 2012 at 04:12:33 UTC, Jay Norwood wrote:
>
> [....]
>
>> Ok, this was the good surprise.  Reading by chunks was faster 
>> than reading the whole file, by several ms.
>>
>> // read files by chunk ...!better than full input
>> //finished! time: 23 ms
>> void wcp_files_by_chunk(string fn)
>> {
>> 	auto f = File(fn);
>> 	foreach(chunk; f.byChunk(1_000_000)){
>> 	}
>> }
>

mmm, I just looked in std/file.d and std/stdio.d.
The std.file.read() function calls GetFileSize()
before reading, and you are dealing with very tight
differences (23ms vs 31ms). So there is a chance that
either the difference is accounted for by the extra
GetFileSize() (and extra stat() in the posix version),
or your threads/process loosing their scheduled slice
for that extra I/O call of GetFileSize().
   Also, in windows, std.file.read() uses ReadFile, while
byChunk uses fread(), though it should all be the same
in the end.

   It is better to try with files big enough to see whether
the timing difference gets either bigger or stays
just around those 8ms.

I'll later try all this too!!! Nice benchmarking
by the way!! Got me interested!

--jm





More information about the Digitalmars-d mailing list