A benchmark's runtime can depend on the presence/absence of other benchmarks
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- haskell
- 领域
- performance
调研方向
首先,使用 GHC 7.8.3、criterion-1.0.0.2 和 -O2 -fllvm 重现 issue 中所示的两个 Criterion 基准测试变体。比较有无 VU.sum 基准测试时的运行时间和生成的 Core,然后确定结果是否需要修改 Criterion 或编写更清晰的文档;当行为和任何拟议的解决方案都已确定时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
The following code compares two functions for summing over a vector:
{-# LANGUAGE BangPatterns #-}
import Control.DeepSeq
import Criterion
import Criterion.Main
import Data.Vector.Unboxed as VU
import Data.Vector.Generic as VG
import qualified Data.Vector.Fusion.Stream as Stream
sumV :: (VG.Vector v a, Num a) => v a -> a
sumV = Stream.foldl' (+) 0 . VG.stream
main = do
let v10 = VU.fromList [0..9] :: VU.Vector Double
deepseq v10 $ return ()
defaultMain
[ bench "sumV" $ nf sumV v10
]
But suppose I change the last few lines to the following:
defaultMain
[ bench "sumV" $ nf sumV v10
, bench "VU.sum" $ nf VU.sum v10 -- Added this line
]
This, surprisingly, affects the runtime of the sumV benchmark. It makes it about 20% faster. Similarly, if we remove the sumV benchmark and leave the VU.sum benchmark, the VU.sum benchmark becomes about 20% slower. Tests were run with the patched criterion-1.0.0.2 I sent on ghc-7.8.3 with the -O2 -fllvm flags.
What's going on is that different core is generated for the sumV and VU.sum benchmarks depending on whether the other benchmark is present. Essentially, the common bits are being factored out and placed in a function, and this function is getting called in both benchmarks. This happens to make both benchmarks faster.
I'm not sure if this should be considered a "proper bug," but it confused me for a an hour or so. It's something that criterion users (especially those performing really small benchmarks) probably should be aware of.
- 主要语言
- Haskell
- 星标
- 525
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
haskell/criterion 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 48/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
难度 1/5 1-3 小时 新手友好度 48/100
查看 haskell/criterion 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
haskell/bytestring#730 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
seal-harness/seal-harness#399 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
fmidue/codeworld-tasks#124 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
reflex-frp/reflex#563 ·