/usr/bin/openssl on macOS High Sierra is crazy slow at checksumming

I upgraded to macOS 10.13 High Sierra and found /usr/bin/openssl to be ridiculously slow at checksumming. Not really sure why, but below I show some benchmarks for SHA-1 with system openssl(1), brewed OpenSSL, brewed LibreSSL, and brewed GNU coreutils. Disk cache is primed in all cases, and disk I/O shouldn’t be the bottleneck in any case, since I can read at at least 1.5GB/s on the builtin SSD on my Mid-2015 15” rMBP. For large files, e.g. 100MiB or 1GiB, the throughput of brewed OpenSSL (1.0.2l) is ~700MiB/s, while the throughput of system openssl(1) (LibreSSL 2.2.7) is ~70MiB/s, i.e. ~10 times slower, which is simply ridiculous. This was not true for macOS 10.12 Sierra, where I recall at least 300MiB/s with system openssl(1). Results for MD5 and SHA-256 are similar.

$ /usr/local/opt/openssl/bin/openssl version
OpenSSL 1.0.2l  25 May 2017
$ /usr/local/opt/libressl/bin/openssl version
LibreSSL 2.5.5
$ /usr/bin/openssl version
LibreSSL 2.2.7
$ /usr/local/opt/coreutils/libexec/gnubin/sha1sum --version
sha1sum (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Ulrich Drepper, Scott Miller, and David Madore.

1GiB file:

$ bench '/usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/1GiB.bin'
benchmarking /usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/1GiB.bin
time                 1.468 s    (1.445 s .. 1.480 s)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 1.466 s    (1.463 s .. 1.470 s)
std dev              3.361 ms   (0.0 s .. 3.626 ms)
variance introduced by outliers: 19% (moderately inflated)

$ bench '/usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/1GiB.bin'
benchmarking /usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/1GiB.bin
time                 1.683 s    (1.293 s .. 2.146 s)
                     0.991 R²   (0.970 R² .. 1.000 R²)
mean                 1.816 s    (1.741 s .. 1.891 s)
std dev              129.7 ms   (0.0 s .. 130.0 ms)
variance introduced by outliers: 20% (moderately inflated)

$ bench -L 180 '/usr/bin/openssl dgst -sha1 /tmp/1GiB.bin'
benchmarking /usr/bin/openssl dgst -sha1 /tmp/1GiB.bin
time                 14.26 s    (NaN s .. 14.71 s)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 14.46 s    (14.30 s .. 14.55 s)
std dev              143.1 ms   (0.0 s .. 162.0 ms)
variance introduced by outliers: 19% (moderately inflated)

$ bench '/usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/1GiB.bin'
benchmarking /usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/1GiB.bin
time                 2.301 s    (2.158 s .. 2.500 s)
                     0.999 R²   (0.999 R² .. 1.000 R²)
mean                 2.372 s    (2.318 s .. 2.409 s)
std dev              54.68 ms   (0.0 s .. 63.13 ms)
variance introduced by outliers: 19% (moderately inflated)

100MiB file:

$ bench '/usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/100MiB.bin'
benchmarking /usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/100MiB.bin
time                 145.1 ms   (140.7 ms .. 150.7 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 139.2 ms   (136.1 ms .. 142.0 ms)
std dev              4.040 ms   (2.732 ms .. 5.067 ms)
variance introduced by outliers: 12% (moderately inflated)

$ bench '/usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/100MiB.bin'
benchmarking /usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/100MiB.bin
time                 165.4 ms   (160.1 ms .. 170.8 ms)
                     0.999 R²   (0.995 R² .. 1.000 R²)
mean                 170.4 ms   (167.9 ms .. 174.0 ms)
std dev              4.133 ms   (2.919 ms .. 5.442 ms)
variance introduced by outliers: 12% (moderately inflated)

$ bench '/usr/bin/openssl dgst -sha1 /tmp/100MiB.bin'
benchmarking /usr/bin/openssl dgst -sha1 /tmp/100MiB.bin
time                 1.366 s    (1.293 s .. 1.402 s)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 1.347 s    (1.329 s .. 1.359 s)
std dev              17.58 ms   (0.0 s .. 20.08 ms)
variance introduced by outliers: 19% (moderately inflated)

$ bench '/usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/100MiB.bin'
benchmarking /usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/100MiB.bin
time                 232.1 ms   (220.2 ms .. 239.5 ms)
                     0.998 R²   (0.993 R² .. 1.000 R²)
mean                 231.9 ms   (228.1 ms .. 236.1 ms)
std dev              4.898 ms   (2.691 ms .. 7.322 ms)
variance introduced by outliers: 14% (moderately inflated)

1MiB file:

$ bench '/usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/1MiB.bin'
benchmarking /usr/local/opt/openssl/bin/openssl dgst -sha1 /tmp/1MiB.bin
time                 8.162 ms   (8.071 ms .. 8.258 ms)
                     0.999 R²   (0.998 R² .. 0.999 R²)
mean                 8.179 ms   (8.126 ms .. 8.251 ms)
std dev              171.2 μs   (141.3 μs .. 207.3 μs)

$ bench '/usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/1MiB.bin'
benchmarking /usr/local/opt/libressl/bin/openssl dgst -sha1 /tmp/1MiB.bin
time                 8.218 ms   (8.081 ms .. 8.418 ms)
                     0.997 R²   (0.994 R² .. 0.999 R²)
mean                 8.177 ms   (8.088 ms .. 8.300 ms)
std dev              293.3 μs   (229.1 μs .. 364.3 μs)
variance introduced by outliers: 14% (moderately inflated)

$ bench '/usr/bin/openssl dgst -sha1 /tmp/1MiB.bin'
benchmarking /usr/bin/openssl dgst -sha1 /tmp/1MiB.bin
time                 19.57 ms   (19.11 ms .. 19.96 ms)
                     0.997 R²   (0.994 R² .. 0.999 R²)
mean                 20.09 ms   (19.75 ms .. 20.52 ms)
std dev              850.1 μs   (609.8 μs .. 1.245 ms)
variance introduced by outliers: 13% (moderately inflated)

$ bench '/usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/1MiB.bin'
benchmarking /usr/local/opt/coreutils/libexec/gnubin/sha1sum /tmp/1MiB.bin
time                 7.358 ms   (7.193 ms .. 7.503 ms)
                     0.996 R²   (0.993 R² .. 0.998 R²)
mean                 7.333 ms   (7.243 ms .. 7.457 ms)
std dev              296.7 μs   (236.7 μs .. 408.9 μs)
variance introduced by outliers: 19% (moderately inflated)

Update. I spun up a 10.12 VM and checked. The system openssl(1) on 10.12.6 is actually OpenSSL, despite being a very old version:

$ /usr/bin/openssl version
OpenSSL 0.9.8zh 14 Jan 2016