bench 1.0.6 → 1.0.7
raw patch · 3 files changed
+34/−10 lines, 3 filesdep +process
Dependencies added: process
Files
- README.md +10/−4
- bench.cabal +3/−1
- src/Main.hs +21/−5
README.md view
@@ -1,4 +1,4 @@-# Bench v1.0.6+# Bench v1.0.7 This project provides the `bench` command-line tool, which is a more powerful alternative to the `time` command. Use `bench` to benchmark a command using@@ -14,9 +14,11 @@ ## Quick Start -You can download a pre-built binary for OS X on the releases page:+You can install `bench` on macOS via [Homebrew](http://braumeister.org/formula/bench): -* https://github.com/Gabriel439/bench/releases+```bash+$ brew install bench+``` ... or you can install `bench` using Haskell's `stack` tool. To do that, first download the [Haskell toolchain](https://www.haskell.org/downloads#minimal),@@ -31,7 +33,11 @@ Make sure that the installation directory is on your executable search path before running `bench`. `stack` will remind you to do this if you forget. -Once you've installed `bench` (either by download or installation via `stack`),+Another alternative is to use [Nix package manager](https://nixos.org/nix/). After its installation just execute:++```$ nix-env -i bench```++Once you've installed `bench` (either by download or installation via `stack` or Nix), you can begin benchmarking programs: ```bash
bench.cabal view
@@ -1,5 +1,5 @@ name: bench-version: 1.0.6+version: 1.0.7 synopsis: Command-line benchmark tool description: Think of this as a more powerful alternative to the @time@ command. Use this command-line tool to benchmark a command@@ -28,7 +28,9 @@ build-depends: base >= 4.5 && < 5 , criterion >= 1.1.1.0 && < 1.3 , optparse-applicative >= 0.2.0 && < 0.15+ , process >= 1.3 && < 1.7 , silently >= 1.1.1 && < 1.3 , text < 1.3 , turtle >= 1.2.5 && < 1.5 ghc-options: -Wall -O2 -threaded+ other-modules: Paths_bench
src/Main.hs view
@@ -6,19 +6,23 @@ import Control.Applicative import Data.Monoid ((<>)) import Data.Text (Text)-import Turtle (Parser, s, (%))+import Turtle (ExitCode(..), Parser, ShellFailed(..), s, (%)) +import qualified Control.Exception import qualified Criterion import qualified Criterion.Main as Criterion import qualified Criterion.Main.Options as Criterion import qualified Data.Text as Text+import qualified Data.Version import qualified Options.Applicative+import qualified Paths_bench import qualified System.IO as IO import qualified System.IO.Silently as Silently+import qualified System.Process import qualified Turtle version :: Text-version = "1.0.2"+version = Text.pack (Data.Version.showVersion Paths_bench.version) data Options = Options [Text] Criterion.Mode | Version deriving (Show) @@ -57,7 +61,19 @@ buildBench :: Text -> Criterion.Benchmark buildBench command = do- let io = Turtle.shells command empty+ let createProcess =+ (System.Process.shell (Text.unpack command))+ { System.Process.std_in = System.Process.NoStream+ }++ let io = do+ exitCode <- Turtle.system createProcess empty+ case exitCode of+ ExitFailure _ -> do+ Control.Exception.throwIO (ShellFailed command exitCode)+ _ -> do+ return ()+ let benchmark = Criterion.nfIO (Silently.hSilence [IO.stdout, IO.stderr] io)- let bench = Criterion.bench (Text.unpack command) benchmark- bench++ Criterion.bench (Text.unpack command) benchmark