|
|
|
|
|
by deltaci
1552 days ago
|
|
this is very naive reimplentation of the C# version. I managed to reduce the runtime of the same file from 5.7 seconds to just 800ms using var file = File.OpenRead("file.bin");
var counter = 0;
var sw = Stopwatch.StartNew();
var buf = new byte[4096];
while (file.Read(buf,0,buf.Length) > 0)
{
foreach (var t in buf)
{
if (t == '1')
{
counter++;
}
}
}
sw.Stop();
Console.WriteLine($"Counted {counter:N0} 1s in {sw.Elapsed.TotalMilliseconds:N4} milliseconds");
|
|
(This bug won't affect the performance comparison, but I was just reminded of how error prone these kinds APIs can be vs the PHP/Python route of having the library function just allocate a new buffer each time.)