diff options
Diffstat (limited to 'src/LivingVillage.Desktop')
| -rw-r--r-- | src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj | 1 | ||||
| -rw-r--r-- | src/LivingVillage.Desktop/PerformanceSummary.fs | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj b/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj index 6f388f2..2901dce 100644 --- a/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj +++ b/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj @@ -19,6 +19,7 @@ <Compile Include="SampleScript.fs" /> <Compile Include="M6Presentation.fs" /> <Compile Include="HudLayout.fs" /> + <Compile Include="PerformanceSummary.fs" /> <Compile Include="TitleScreen.fs" /> <Compile Include="Game.fs" /> diff --git a/src/LivingVillage.Desktop/PerformanceSummary.fs b/src/LivingVillage.Desktop/PerformanceSummary.fs new file mode 100644 index 0000000..3edb4a7 --- /dev/null +++ b/src/LivingVillage.Desktop/PerformanceSummary.fs @@ -0,0 +1,27 @@ +namespace LivingVillage.Desktop + +/// P21:纯函数的帧率采样汇总(均值/最低/最高),供实机性能核对与回归测试。 +/// 不含时钟/IO,只看传入的每秒 FPS 样本序列;warmup 采样用于剔除启动抖动。 +module PerformanceSummary = + + type Summary = + { Count: int + Mean: float + Min: float + Max: float } + + /// 丢弃前 `warmupSamples` 个样本(不足则全丢),对剩余样本求均值/最低/最高。 + /// 剩余为空时返回 None(如运行过短)。 + let summarize (warmupSamples: int) (samples: float list) : Summary option = + let skip = max 0 warmupSamples + let taken = + if List.length samples <= skip then [] + else samples |> List.skip skip + match taken with + | [] -> None + | _ -> + Some + { Count = taken.Length + Mean = List.average taken + Min = List.min taken + Max = List.max taken } |
