私は BitConvert の速度を向上させようとしています。むしろ、別の方法です。
だからここに私が思っていたより速いはずのコードがあります:
    bsize = ms.length
    int index = 0;
    byte[] target = new byte[intsize];
    target[index++] = (byte)bsize;
    target[index++] = (byte)(bsize >> 8);
    target[index++] = (byte)(bsize >> 16);
    target[index] = (byte)(bsize >> 24);
そして、BitConvert コード:
BitConverter.GetBytes(bsize)
まあ、それは速くはありませんでした。私のテストではかなり遅く、2 倍以上遅くなりました。
では、なぜ遅いのでしょうか。また、速度を上げる方法はありますか?
編集:
BitConvert = 5068 Ticks
OtherMethod above: 12847 Ticks
編集 2: 私のベンチマーク コード:
private unsafe void ExecuteBenchmark(int samplingSize = 100000)
    {
        // run the Garbage collector
        GC.Collect();
        GC.WaitForPendingFinalizers();
        // log start
        Console.WriteLine("Benchmark started");
        // start timer
        var t = Stopwatch.StartNew();
                for (int i = 0; i < samplingSize; i++)
                {
                }
        }
        // stop timer
        t.Stop();
        // log ending
        Console.WriteLine("Execute1 time = " + t.ElapsedTicks + " ticks");
    }