Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack run single benchmark

I have multiple benchmarks defined in my cabal file:

benchmark my-gauge-bench
  type: exitcode-stdio-1.0
  main-is: Main.hs
  hs-source-dirs:
      bench/gauge
  ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wall -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      QuickCheck
    , base >=4.10 && <10
    , bytestring
    , gauge
  default-language: Haskell2010

benchmark my-weigh-bench
  type: exitcode-stdio-1.0
  main-is: Main.hs
  other-modules:
      Paths_pkg_core_gen
  hs-source-dirs:
      bench/weigh
  ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wall
  build-depends:
      QuickCheck
    , base >=4.10 && <10
    , bytestring
    , weigh

How can I run only single benchmark (like my-guage-bench) using Stack ?

like image 741
Sibi Avatar asked Oct 24 '25 10:10

Sibi


1 Answers

This applies to all targets in stack, be it tests, benchmarks or executables.

There is a cool little command in stack that can help you list all available targets, without resorting to dig through my-package.cabal or package.yaml files. It is especially useful for multi-package projects and will work for all packages listed in packages: field in stack.yaml:

$ stack ide targets
my-package:lib
my-package:test:doctests
my-package:test:tests
my-package:bench:weight
my-package:bench:gauge
another-package:lib
another-package:exe:my-cool-executable
another-package:test:doctests
another-package:test:tests
another-package:bench:weight
another-package:bench:criterion

Now that we know the list we can invoke specific benchmarks

$ stack bench my-package:bench:gauge another-package:bench:criterion
like image 150
lehins Avatar answered Oct 26 '25 04:10

lehins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!