プロジェクトで作業している間に、私は間違いなく1つの追加(未使用)引数を持つ同じメソッドが他のものよりも10倍も高速に実行できることに気付きました。 Stream.Format
よりもはるかに高速 ほぼ同等のメソッド間で素晴らしいパフォーマンスの差
type Stream() =
static member private write (x, o, a : byte[]) = (for i = 0 to 3 do a.[o + i] <- byte((x >>> 24 - i * 8) % 256)); 4
static member private format f x l = Array.zeroCreate l |> fun a -> (f(x, 0, a) |> ignore; a)
static member private format1 f x l o = Array.zeroCreate l |> fun a -> (f(x, 0, a) |> ignore; a)
static member Format (value : int) = Stream.format (fun (x: int, i, a) -> Stream.write(x, i, a)) value 4
static member Format1 (value : int) = Stream.format1 (fun (x: int, i, a) -> Stream.write(x, i, a)) value 4
テスト
、Stream.Format1
実行、プライベートメンバー
Stream.format
と
Stream.format1
の唯一の違いは、さらに法それ自体で使用されていないだけで
o
引数、ですが。
コンパイラはどのようにして異なる方法で2つのほぼ同じ方法を扱いますか?
編集:説明に感謝し、無知にごめんなさい。
あなたがタイミングを取得するために実行しなかったどのように多くの反復? 1? 100万?キャッシュ効果、カーネルスケジューリングなどを円滑にするには、サンプルを十分に広げる必要があります。 – spraff