From ff1b85c1007e5a92a31cac3d09fd7ad5612c5e18 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 22 Jan 2024 16:52:59 +0100 Subject: [PATCH] Add timed and test with GHC 9.8 (#11) --- .github/workflows/haskell-ci.yml | 43 +++++++++++++++++++------------- CHANGELOG.md | 3 +++ monad-time.cabal | 6 +++-- src/Control/Monad/Time/Utils.hs | 13 ++++++++++ 4 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 src/Control/Monad/Time/Utils.hs diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index ef88b3e..d929ee2 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.16.3 +# version: 0.17.20240109 # -# REGENDATA ("0.16.3",["github","--config=cabal.haskell-ci","cabal.project"]) +# REGENDATA ("0.17.20240109",["github","--config=cabal.haskell-ci","cabal.project"]) # name: Haskell-CI on: @@ -32,14 +32,19 @@ jobs: strategy: matrix: include: - - compiler: ghc-9.6.2 + - compiler: ghc-9.8.1 compilerKind: ghc - compilerVersion: 9.6.2 + compilerVersion: 9.8.1 setup-method: ghcup allow-failure: false - - compiler: ghc-9.4.5 + - compiler: ghc-9.6.4 compilerKind: ghc - compilerVersion: 9.4.5 + compilerVersion: 9.6.4 + setup-method: ghcup + allow-failure: false + - compiler: ghc-9.4.8 + compilerKind: ghc + compilerVersion: 9.4.8 setup-method: ghcup allow-failure: false - compiler: ghc-9.2.8 @@ -70,18 +75,18 @@ jobs: apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5 if [ "${{ matrix.setup-method }}" = ghcup ]; then mkdir -p "$HOME/.ghcup/bin" - curl -sL https://downloads.haskell.org/ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 > "$HOME/.ghcup/bin/ghcup" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$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) + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) else apt-add-repository -y 'ppa:hvr/ghc' apt-get update apt-get install -y "$HCNAME" mkdir -p "$HOME/.ghcup/bin" - curl -sL https://downloads.haskell.org/ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 > "$HOME/.ghcup/bin/ghcup" + curl -sL https://downloads.haskell.org/ghcup/0.1.20.0/x86_64-linux-ghcup-0.1.20.0 > "$HOME/.ghcup/bin/ghcup" chmod a+x "$HOME/.ghcup/bin/ghcup" - "$HOME/.ghcup/bin/ghcup" install cabal 3.10.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false) + "$HOME/.ghcup/bin/ghcup" install cabal 3.10.2.0 || (cat "$HOME"/.ghcup/logs/*.* && false) fi env: HCKIND: ${{ matrix.compilerKind }} @@ -95,17 +100,19 @@ jobs: echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV" HCDIR=/opt/$HCKIND/$HCVER if [ "${{ matrix.setup-method }}" = ghcup ]; then - 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 "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "HCPKG=$HCPKG" >> "$GITHUB_ENV" + echo "HADDOCK=$HADDOCK" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" else HC=$HCDIR/bin/$HCKIND echo "HC=$HC" >> "$GITHUB_ENV" echo "HCPKG=$HCDIR/bin/$HCKIND-pkg" >> "$GITHUB_ENV" echo "HADDOCK=$HCDIR/bin/haddock" >> "$GITHUB_ENV" - echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.1.0 -vnormal+nowrap" >> "$GITHUB_ENV" + echo "CABAL=$HOME/.ghcup/bin/cabal-3.10.2.0 -vnormal+nowrap" >> "$GITHUB_ENV" fi HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))') @@ -157,7 +164,7 @@ jobs: - name: cache (tools) uses: actions/cache/restore@v3 with: - key: ${{ runner.os }}-${{ matrix.compiler }}-tools-ee7e0b4e + key: ${{ runner.os }}-${{ matrix.compiler }}-tools-a85c2722 path: ~/.haskell-ci-tools - name: install cabal-plan run: | @@ -170,13 +177,13 @@ jobs: cabal-plan --version - name: install doctest run: | - if [ $((HCNUMVER < 90600)) -ne 0 ] ; then $CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.20' ; fi + if [ $((HCNUMVER < 90600)) -ne 0 ] ; then $CABAL --store-dir=$HOME/.haskell-ci-tools/store v2-install $ARG_COMPILER --ignore-project -j2 doctest --constraint='doctest ^>=0.22' ; fi if [ $((HCNUMVER < 90600)) -ne 0 ] ; then doctest --version ; fi - name: save cache (tools) uses: actions/cache/save@v3 if: always() with: - key: ${{ runner.os }}-${{ matrix.compiler }}-tools-ee7e0b4e + key: ${{ runner.os }}-${{ matrix.compiler }}-tools-a85c2722 path: ~/.haskell-ci-tools - name: checkout uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 586baaf..4d01e7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# monad-time-0.4.1.0 (2024-??-??) +* Added `timed` function to `Control.Monad.Time.Utils`. + # monad-time-0.4.0.0 (2022-07-05) * Added `monotonicTime` to `MonadTime` * Removed the `MonadTime` instance for `ReaderT UTCTime` diff --git a/monad-time.cabal b/monad-time.cabal index 3f28f5f..e1044ff 100644 --- a/monad-time.cabal +++ b/monad-time.cabal @@ -1,5 +1,5 @@ name: monad-time -version: 0.4.0.0 +version: 0.4.1.0 synopsis: Type class for monads which carry the notion of the current time. description: 'MonadTime' type class for monads @@ -14,7 +14,8 @@ category: Control build-type: Simple cabal-version: >=1.10 extra-source-files: README.md CHANGELOG.md -tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.5 || ==9.6.2 +tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.4 + || ==9.8.1 source-repository head type: git @@ -22,6 +23,7 @@ source-repository head library exposed-modules: Control.Monad.Time + Control.Monad.Time.Utils build-depends: base >=4.13 && < 5, mtl, diff --git a/src/Control/Monad/Time/Utils.hs b/src/Control/Monad/Time/Utils.hs new file mode 100644 index 0000000..92787aa --- /dev/null +++ b/src/Control/Monad/Time/Utils.hs @@ -0,0 +1,13 @@ +module Control.Monad.Time.Utils + ( timed + ) where + +import Control.Monad.Time + +-- | Measure how much time a monadic action takes. +timed :: MonadTime m => m r -> m (r, Double) +timed mr = do + t1 <- monotonicTime + r <- mr + t2 <- monotonicTime + r `seq` pure (r, t2 - t1)