SELECT DISTINCT
TestName
,[BatchSize]
,[Iterations] = COUNT(*) OVER(PARTITION BY TestName, [BatchSize])
,[Min] = PERCENTILE_DISC(0) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[5th] = PERCENTILE_DISC(0.05) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[10th] = PERCENTILE_DISC(0.1) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[25th] = PERCENTILE_DISC(0.25) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[Avg] = PERCENTILE_DISC(0.5) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[75th] = PERCENTILE_DISC(0.75) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[90th] = PERCENTILE_DISC(0.9) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[95th] = PERCENTILE_DISC(0.95) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[Max] = PERCENTILE_DISC(1) WITHIN GROUP(ORDER BY RuntimeMs) OVER(PARTITION BY TestName, [BatchSize])
,[StdDev] = SQRT((
(COUNT(RuntimeMs) OVER (PARTITION BY TestName, [BatchSize])
* SUM(RuntimeMs*RuntimeMs) OVER (PARTITION BY TestName, [BatchSize]))
- POWER(SUM(RuntimeMs) OVER (PARTITION BY TestName, [BatchSize]), 2))
/ (COUNT(RuntimeMs) OVER (PARTITION BY TestName, [BatchSize])
* COUNT(RuntimeMs) OVER (PARTITION BY TestName, [BatchSize]) - 1))
FROM #TimingResult
我在这里找到了解决方案。本质上,您必须使用统计信息来计算它:
PS 在性能测试代码时随意使用此语句。这就是我写它的原因(特别是针对这个问题)。