deltaci's comments

deltaci | 4 years ago | on: Yes, PHP is faster than C#

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");
page 1