简体   繁体   English

如何使用堆栈标准

[英]How to use criterion with stack

I set up a simple stack project, and a .cabal entry for the benchmark tests: 我设置了一个简单的堆栈项目,以及基准测试的.cabal条目:

benchmark leaves-of-a-tree-bench
  type:             exitcode-stdio-1.0
  hs-source-dirs:   src, bench
  main-is:          MainBenchmarkSuite.hs
  build-depends:    base
                  , criterion
                  , random
                  , leaves-of-a-tree
  ghc-options:      -Wall
                    -O2
  default-language: Haskell2010                    

However after running stack bench I get the following error: 但是在运行stack bench我收到以下错误:

setup-Simple-Cabal-1.22.5.0-ghc-7.10.3: Error: Could not find benchmark program      
".stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/leaves-of-a-tree-bench/leaves-of-a-tree-bench".
Did you build the package first?

Am I missing something? 我错过了什么吗?

EDIT: I uploaded the project to a github repository 编辑:我将项目上传到github存储库

There is some weird cabal stuff going on here. 这里有一些奇怪的阴谋集团。

Your LeavesOfATreeBench.hs : 你的LeavesOfATreeBench.hs

-- |

module LeavesOfATreeBench where

import           Criterion.Main
import           Data.BinTree

mkTree :: [a] -> BinTree a
mkTree [] = Nil
mkTree (x:xs) = Fork x (mkTree lxs) (mkTree rxs)
  where (lxs, rxs) = splitAt ((length xs + 1) `div` 2) xs

main :: IO ()
main = defaultMain [
  bgroup "leaves"
    [ bench "tree 0" $ whnf leaves (mkTree ([0 .. 20] :: [Integer]))
    , bench "tree 1" $ whnf leaves (mkTree ([0 .. 200] :: [Integer]))
    ]
  ]

Now, once I simply remove the line 现在,一旦我删除该行

module LeavesOfATreeBench where

everything works as expected: 一切按预期工作:

Registering leaves-of-a-tree-0.1.0.0...
leaves-of-a-tree-0.1.0.0: benchmarks
Running 1 benchmarks...
Benchmark leaves-of-a-tree-bench: RUNNING...
benchmarking leaves/tree 0
time                 41.81 ns   (41.51 ns .. 42.29 ns)
                     0.999 R²   (0.998 R² .. 0.999 R²)
mean                 42.65 ns   (42.12 ns .. 43.50 ns)
std dev              2.293 ns   (1.526 ns .. 3.690 ns)
variance introduced by outliers: 75% (severely inflated)

benchmarking leaves/tree 1
time                 71.11 ns   (70.41 ns .. 71.84 ns)
                     0.999 R²   (0.999 R² .. 0.999 R²)
mean                 71.30 ns   (70.45 ns .. 72.19 ns)
std dev              2.917 ns   (2.431 ns .. 3.507 ns)
variance introduced by outliers: 62% (severely inflated)

Benchmark leaves-of-a-tree-bench: FINISH
Completed 2 action(s).

This reminds me of what happens when you don't have a proper Main module. 这让我想起了当你没有合适的主模块时会发生什么。 Do you have "module MainBenchmarkSuite" at the top? 你顶部有“模块MainBenchmarkSuite”吗?

I can't find the ghc ticket for this, but for some reason ghc treats this as only a warning. 我找不到这个ghc票,但由于某种原因,ghc认为这只是一个警告。 IIRC it's resolved in GHC 8.0 IIRC已在GHC 8.0中得到解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM