commit a4c17689cd66e1ef35c667914765cb24c9a4b305
parent 282fa90825bbc04c324c58186da473cb380d0fc2
Author: Jared Tobin <jared@jtobin.io>
Date: Mon, 22 Dec 2025 17:02:35 -0330
meta: add llvm flag
Update benchmarks accordingly.
Diffstat:
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
@@ -56,23 +56,23 @@ Haddocks (API documentation, etc.) are hosted at
## Performance
The aim is best-in-class performance for pure, highly-auditable Haskell
-code.
+code. You should compile with the 'llvm' flag for maximum performance.
Current benchmark figures on an M4 Silicon MacBook Air look like (use
`cabal bench` to run the benchmark suite):
```
benchmarking ppad-sha256/SHA256 (32B input)/hash
- time 879.7 ns (879.5 ns .. 879.9 ns)
+ time 265.9 ns (265.7 ns .. 266.1 ns)
1.000 R² (1.000 R² .. 1.000 R²)
- mean 880.1 ns (879.5 ns .. 882.1 ns)
- std dev 3.504 ns (994.6 ps .. 7.537 ns)
+ mean 266.3 ns (266.1 ns .. 266.5 ns)
+ std dev 645.1 ps (524.2 ps .. 829.3 ps)
benchmarking ppad-sha256/HMAC-SHA256 (32B input)/hmac
- time 3.322 μs (3.322 μs .. 3.322 μs)
- 1.000 R² (1.000 R² .. 1.000 R²)
- mean 3.321 μs (3.317 μs .. 3.323 μs)
- std dev 10.53 ns (4.987 ns .. 19.12 ns)
+ time 877.7 ns (872.1 ns .. 886.0 ns)
+ 1.000 R² (0.999 R² .. 1.000 R²)
+ mean 873.3 ns (871.5 ns .. 877.5 ns)
+ std dev 8.491 ns (4.940 ns .. 15.65 ns)
```
Compare this to Hackage's venerable SHA package:
diff --git a/flake.nix b/flake.nix
@@ -25,6 +25,7 @@
pkgs = import nixpkgs { inherit system; };
hlib = pkgs.haskell.lib;
+ llvm = pkgs.llvmPackages_15.llvm;
base16 = ppad-base16.packages.${system}.default;
@@ -50,10 +51,9 @@
buildInputs = [
cabal
cc
+ llvm
];
- inputsFrom = builtins.attrValues self.packages.${system};
-
doBenchmark = true;
shellHook = ''
@@ -62,6 +62,7 @@
echo "cc: $(${cc}/bin/cc --version)"
echo "ghc: $(${ghc}/bin/ghc --version)"
echo "cabal: $(${cabal}/bin/cabal --version)"
+ echo "llc: $(${llvm}/bin/llc --version | head -2 | tail -1)"
'';
};
}
diff --git a/ppad-sha256.cabal b/ppad-sha256.cabal
@@ -14,6 +14,11 @@ description:
A pure implementation of SHA-256 and HMAC-SHA256 on strict and lazy
ByteStrings, as specified by RFC's 6234 and 2104.
+flag llvm
+ description: Use GHC's LLVM backend.
+ default: False
+ manual: True
+
source-repository head
type: git
location: git.ppad.tech/sha256.git
@@ -23,6 +28,8 @@ library
hs-source-dirs: lib
ghc-options:
-Wall
+ if flag(llvm)
+ ghc-options: -fllvm -O2
exposed-modules:
Crypto.Hash.SHA256
build-depends: