簡體   English   中英

如何使用堆棧標准

[英]How to use criterion with stack

我設置了一個簡單的堆棧項目,以及基准測試的.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                    

但是在運行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?

我錯過了什么嗎?

編輯:我將項目上傳到github存儲庫

這里有一些奇怪的陰謀集團。

你的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]))
    ]
  ]

現在,一旦我刪除該行

module LeavesOfATreeBench where

一切按預期工作:

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).

這讓我想起了當你沒有合適的主模塊時會發生什么。 你頂部有“模塊MainBenchmarkSuite”嗎?

我找不到這個ghc票,但由於某種原因,ghc認為這只是一個警告。 IIRC已在GHC 8.0中得到解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM