Skip to content

Commit

Permalink
inline park-bench-internal again, bump some upper bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Oct 11, 2023
1 parent 06a123f commit e6e61b6
Show file tree
Hide file tree
Showing 26 changed files with 223 additions and 277 deletions.
44 changes: 19 additions & 25 deletions .github/workflows/haskell-ci.yml
@@ -1,16 +1,16 @@
# This GitHub workflow config has been generated by a script via
#
# haskell-ci 'github' 'cabal.project'
# haskell-ci 'github' 'park-bench.cabal'
#
# To regenerate the script (for example after adjusting tested-with) run
#
# haskell-ci regenerate
#
# For more information, see https://github.com/haskell-CI/haskell-ci
#
# version: 0.15.20230312
# version: 0.17.20231010
#
# REGENDATA ("0.15.20230312",["github","cabal.project"])
# REGENDATA ("0.17.20231010",["github","park-bench.cabal"])
#
name: Haskell-CI
on:
Expand All @@ -28,19 +28,19 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.6.1
- compiler: ghc-9.8.1
compilerKind: ghc
compilerVersion: 9.6.1
compilerVersion: 9.8.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.4.4
- compiler: ghc-9.6.3
compilerKind: ghc
compilerVersion: 9.4.4
compilerVersion: 9.6.3
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.2.7
- compiler: ghc-9.4.7
compilerKind: ghc
compilerVersion: 9.2.7
compilerVersion: 9.4.7
setup-method: ghcup
allow-failure: false
fail-fast: false
Expand All @@ -50,7 +50,7 @@ jobs:
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.18.0/x86_64-linux-ghcup-0.1.18.0 > "$HOME/.ghcup/bin/ghcup"
curl -sL https://downloads.haskell.org/ghcup/0.1.19.5/x86_64-linux-ghcup-0.1.19.5 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
Expand All @@ -65,10 +65,12 @@ jobs:
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
HC=$HOME/.ghcup/bin/$HCKIND-$HCVER
HC=$("$HOME/.ghcup/bin/ghcup" whereis ghc "$HCVER")
HCPKG=$(echo "$HC" | sed 's#ghc$#ghc-pkg#')
HADDOCK=$(echo "$HC" | sed 's#ghc$#haddock#')
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
echo "HCPKG=$HCPKG" >> "$GITHUB_ENV"
echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
Expand Down Expand Up @@ -119,8 +121,8 @@ jobs:
- name: install cabal-plan
run: |
mkdir -p $HOME/.cabal/bin
curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.6.2.0/cabal-plan-0.6.2.0-x86_64-linux.xz > cabal-plan.xz
echo 'de73600b1836d3f55e32d80385acc055fd97f60eaa0ab68a755302685f5d81bc cabal-plan.xz' | sha256sum -c -
curl -sL https://github.com/haskell-hvr/cabal-plan/releases/download/v0.7.3.0/cabal-plan-0.7.3.0-x86_64-linux.xz > cabal-plan.xz
echo 'f62ccb2971567a5f638f2005ad3173dba14693a45154c1508645c52289714cb2 cabal-plan.xz' | sha256sum -c -
xz -d < cabal-plan.xz > $HOME/.cabal/bin/cabal-plan
rm -f cabal-plan.xz
chmod a+x $HOME/.cabal/bin/cabal-plan
Expand All @@ -132,8 +134,7 @@ jobs:
- name: initial cabal.project for sdist
run: |
touch cabal.project
echo "packages: $GITHUB_WORKSPACE/source/park-bench" >> cabal.project
echo "packages: $GITHUB_WORKSPACE/source/park-bench-internal" >> cabal.project
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
cat cabal.project
- name: sdist
run: |
Expand All @@ -147,20 +148,15 @@ jobs:
run: |
PKGDIR_park_bench="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/park-bench-[0-9.]*')"
echo "PKGDIR_park_bench=${PKGDIR_park_bench}" >> "$GITHUB_ENV"
PKGDIR_park_bench_internal="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/park-bench-internal-[0-9.]*')"
echo "PKGDIR_park_bench_internal=${PKGDIR_park_bench_internal}" >> "$GITHUB_ENV"
rm -f cabal.project cabal.project.local
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_park_bench}" >> cabal.project
echo "packages: ${PKGDIR_park_bench_internal}" >> cabal.project
echo "package park-bench" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
echo "package park-bench-internal" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(park-bench|park-bench-internal)$/; }' >> cabal.project.local
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(park-bench)$/; }' >> cabal.project.local
cat cabal.project
cat cabal.project.local
- name: dump install plan
Expand All @@ -187,8 +183,6 @@ jobs:
run: |
cd ${PKGDIR_park_bench} || false
${CABAL} -vnormal check
cd ${PKGDIR_park_bench_internal} || false
${CABAL} -vnormal check
- name: haddock
run: |
$CABAL v2-haddock --disable-documentation --haddock-all $ARG_COMPILER --with-haddock $HADDOCK $ARG_TESTS $ARG_BENCH all
Expand Down
3 changes: 1 addition & 2 deletions park-bench/CHANGELOG.md → CHANGELOG.md
@@ -1,7 +1,6 @@
## [0.1.1.0] - Unreleased
## [0.1.1.0] - 23-10-10

- Accept `PARK_BENCH_RUNLEN` env var
- Move `ParkBench.Internal` into its own package `park-bench-internal`

## [0.1.0.1] - 22-08-06

Expand Down
2 changes: 1 addition & 1 deletion park-bench/LICENSE → LICENSE
@@ -1,4 +1,4 @@
Copyright 2020-2022 Mitchell Rosen, Travis Staton
Copyright 2020-2023 Mitchell Rosen, Travis Staton

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
1 change: 0 additions & 1 deletion README.md

This file was deleted.

111 changes: 111 additions & 0 deletions README.md
@@ -0,0 +1,111 @@
[![GitHub CI](https://github.com/awkward-squad/park-bench/workflows/Haskell-CI/badge.svg)](https://github.com/awkward-squad/park-bench/actions?query=workflow%3AHaskell-CI) |
[![Hackage](https://img.shields.io/hackage/v/park-bench.svg?label=park-bench&logo=haskell)](https://hackage.haskell.org/package/park-bench)
[![Stackage LTS](https://stackage.org/package/park-bench/badge/lts)](https://www.stackage.org/lts/package/park-bench)
[![Stackage Nightly](https://stackage.org/package/park-bench/badge/nightly)](https://www.stackage.org/nightly/package/park-bench)
[![Dependencies](https://img.shields.io/hackage-deps/v/park-bench)](https://packdeps.haskellers.com/reverse/park-bench)

# Overview

`park-bench` is a quick-and-dirty benchmarking tool for comparing the performance of Haskell functions. Specifically, it
is designed to optimize the workflow in which a programmer makes a small change to a function and wants to measure its
performance impact with as little friction as possible.

![Screenshot](https://github.com/awkward-squad/park-bench/blob/main/images/screenshot.png?raw=true)

# Configuration

| Environment variable name | Type | Meaning | Default value |
| --- | --- | --- | --- |
| `PARK_BENCH_RUNLEN` | Float | The target number of seconds that each benchmark run takes | `0.1` |

# Example usage

Say I am interested in improving the performance of `fib`, which is a function defined in module `MyMathUtilities.Fib`
in a local package called `my-math-utilities`.

## Step 1: Write the function you'd like to benchmark

First, I'm going to copy the implementation of `fib` to a new top-level definition called `fastfib`, tweak its
implementation, and export both from module `MyMathUtilities.Fib`.

If `fib` was private before, that's ok. We only need to expose it for as long as we are interested in benchmarking.

```haskell
module MyMathUtilities.Fib (fib, fastfib, ...) where
```

## Step 2: Write a standalone `bench/Main.hs` module with a `main` function

Next, I'm going to write a standalone `Main.hs` in a subdirectory called `bench`, which will be compiled to an
executable that runs my benchmark.

```haskell
module Main where

-- The module in my local package that I want to benchmark
import MyMathUtilities.Fib

-- This library
import ParkBench

main :: IO ()
main =
benchmark
[ function "fib" fib 20
, function "fastfib" fastfib 20
]
```

## Step 3: Define an executable component

Next, I'm going to define an executable component for my benchmark in my `my-math-utilities.cabal` file.

```cabal
executable bench
build-depends:
base,
-- The local package that I want to benchmark
my-math-utilities,
-- This library
park-bench
default-language: Haskell2010
ghc-options: -O -rtsopts -with-rtsopts=-T
hs-source-dirs: bench
main-is: Main.hs
```

I need to compile the benchmark with `-rtsopts -with-rtsopts=-T`, otherwise my benchmark will not be able to get RTS
statistics from GHC at runtime.

Alternatively, I could compile the benchmark with only `-rtsopts`, but then I'll have to provide `+RTS -T` to the
executable later.

## Step 4: Run the benchmark

If all goes well, I'll have an executable component to run.

```
cabal run my-math-utilities:exe:bench
```
```
stack run my-math-utilities:exe:bench
```

Or, if I only compiled with `-rtsopts`, but not `-with-rtsopts=-T`,

```
cabal run my-math-utilities:exe:bench -- +RTS -T
```
```
stack run my-math-utilities:exe:bench -- +RTS -T
```

## Step 5: Clean up

After benchmarking, I can choose to keep the benchmark (and associated executable component) around, but I'll probably
delete them instead. I've learned something, collected some sweet screenshots for my PR, and I'm ready to move on.

# Caveat emptor

The statistical analysis performed by `park-bench` is simplistic, written by a novice, and may have bugs. Results should
not necessarily be trusted; please use (or at least compare to) a different tool.
3 changes: 0 additions & 3 deletions cabal.project

This file was deleted.

File renamed without changes
3 changes: 0 additions & 3 deletions park-bench-internal/CHANGELOG.md

This file was deleted.

11 changes: 0 additions & 11 deletions park-bench-internal/LICENSE

This file was deleted.

54 changes: 31 additions & 23 deletions ...-bench-internal/park-bench-internal.cabal → park-bench.cabal
Expand Up @@ -3,22 +3,26 @@ cabal-version: 2.2
author: Mitchell Rosen, Travis Staton
bug-reports: https://github.com/awkward-squad/park-bench/issues
category: Benchmarking
copyright: Copyright (C) 2020-2022 Mitchell Rosen, Travis Staton
copyright: Copyright (C) 2020-2023 Mitchell Rosen, Travis Staton
homepage: https://github.com/awkward-squad/park-bench
license: BSD-3-Clause
license-file: LICENSE
maintainer: Mitchell Rosen <mitchellwrosen@gmail.com>, Travis Staton <hello@travisstaton.com>
name: park-bench-internal
name: park-bench
stability: experimental
synopsis: @park-bench@ internals
tested-with: GHC == 9.2.7, GHC == 9.4.4, GHC == 9.6.1
version: 0.1.0
synopsis: A quick-and-dirty, low-friction benchmark tool with immediate feedback
tested-with: GHC == 9.4.7, GHC == 9.6.3, GHC == 9.8.1
version: 0.1.1.0

description:
@park-bench@ internals.
A quick-and-dirty, low-friction benchmark tool with immediate feedback.

extra-doc-files:
images/*.png

extra-source-files:
CHANGELOG.md
README.md

source-repository head
type: git
Expand All @@ -27,10 +31,10 @@ source-repository head
library
build-depends:
array ^>= 0.5,
base ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 || ^>= 4.18,
bytestring ^>= 0.10 || ^>= 0.11,
ghc-prim ^>= 0.3 || ^>= 0.4 || ^>= 0.5 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10,
text ^>= 1.1 || ^>= 1.2 || ^>= 2.0,
base ^>= 4.12 || ^>= 4.13 || ^>= 4.14 || ^>= 4.15 || ^>= 4.16 || ^>= 4.17 || ^>= 4.18 || ^>= 4.19,
bytestring ^>= 0.10 || ^>= 0.11 || ^>= 0.12,
ghc-prim ^>= 0.3 || ^>= 0.4 || ^>= 0.5 || ^>= 0.6 || ^>= 0.7 || ^>= 0.8 || ^>= 0.9 || ^>= 0.10 || ^>= 0.11,
text ^>= 1.1 || ^>= 1.2 || ^>= 2.0 || ^>= 2.1,
default-extensions:
AllowAmbiguousTypes
BangPatterns
Expand Down Expand Up @@ -64,19 +68,7 @@ library
ViewPatterns
default-language: Haskell2010
exposed-modules:
ParkBench.Internal.Array1
ParkBench.Internal.Benchable
ParkBench.Internal.Builder
ParkBench.Internal.Config
ParkBench.Internal.Driver
ParkBench.Internal.Measure
ParkBench.Internal.Named
ParkBench.Internal.Prelude
ParkBench.Internal.Pretty
ParkBench.Internal.Render
ParkBench.Internal.RtsStats
ParkBench.Internal.Statistics
ParkBench.Internal.Terminal
ParkBench
ghc-options:
-Weverything
-Wno-all-missed-specialisations
Expand All @@ -92,6 +84,22 @@ library
if impl(ghc >= 9.2)
ghc-options:
-Wno-missing-kind-signatures
if impl(ghc >= 9.8)
ghc-options:
-Wno-missing-role-annotations
hs-source-dirs: src
other-modules:
ParkBench.Internal.Array1
ParkBench.Internal.Benchable
ParkBench.Internal.Benchable.Internal
ParkBench.Internal.Builder
ParkBench.Internal.Config
ParkBench.Internal.Driver
ParkBench.Internal.Measure
ParkBench.Internal.Named
ParkBench.Internal.Prelude
ParkBench.Internal.Pretty
ParkBench.Internal.Render
ParkBench.Internal.RtsStats
ParkBench.Internal.Statistics
ParkBench.Internal.Terminal

0 comments on commit e6e61b6

Please sign in to comment.