Skip to content

Instantly share code, notes, and snippets.

@larskuhtz
Last active June 10, 2019 21:53
Show Gist options
  • Save larskuhtz/62ef355eba9da7729e404a4d6ff44e42 to your computer and use it in GitHub Desktop.
Save larskuhtz/62ef355eba9da7729e404a4d6ff44e42 to your computer and use it in GitHub Desktop.
Microbenchmarks for comparing time and thyme packages

Compile with

ghc -O2 -threaded -package time-1.8.0.2 -package thyme-0.3.5.5 Main.hs

Run as

./Main -o out.html

Results are from a MacBook Pro (15-inc, 2017), 2.9 GHz Intel Core i7, 16GB 2133 MHz LPDDR3.

Summary

getCurrentTime: time, thyme, and time-exts perform equal. hourglass is much slower, for which is reason probably is that the benchmark code uses DateTime as internal representation for time in houglass which requires converting the system timestamp into a calendar format.

Parsing and Formatting: For parsing hourglass is the fastest library. The benchmark use DateTime for representing time in hourglass, which makes creation from timestamps slower but gives this library a benefit for parsing and formatting calendar based time strings. The main reason for the performance of hourglass is most likely the rather simple formatting capabilities along with hand-rolled linear parsing and formatting code. thyme is somewhat slower on formatting and about two times slower for parsing. Formatting with time is about three times slower and parsing with time and times-exts are about seven times slower than hourglass.

Adding offsets: thyme is fastest. time-exts is somewhat slower. time is about two orders of magnitude slower than thyme and hourglass ranges in between thyme and time. Performance for all packages is well below one microsecond.

Time Libraries on Hackage

time

The package represents UTCTime as modified Julian date time. Time offsets are presented with pico-second precision as FIXED E12, which uses Integer. Date offsets are represented as Integer values.

The package has a rich and clean API and follows common standards. It is well maintained and widely supported throughout the Haskell ecosystem.

It has the most powerful and consistent format strings of all Haskell time packages.

The parser is based on ReadP which resolves non-determinism with a list monad effectively computing all possible parser runs in parallel.

thyme

The package aims to be be a feature complete but more efficient reimplementation of the time package with an API that provides full backward compatibility with time.

It achieves performance by limiting the precision to microseconds and a performance optimized implementation. Internally it represents UTCTime as a single Int64 offset.

The package isn't maintained. The version on GitHub as substantial changes compared to the latest released Hackage version. Both version have diverged significantly from the latest versions of the time package.

The format strings of the latest Hackage version are compatible with the format strings of old versions of the time package. The format strings of the GitHub version are incompatible with the extensions of format strings of recent version of the time package.

The parser is based on attoparsec. It creates the grammar productions for time strings on the fly from the format string.

hourglass

The package is intended to be a simple and efficient time package that provides features that are sufficient for most, but not all, circumstances. Internal representation and the implementation of conversions and arithmetic is less efficient than with thyme. The standard representation of time is in second and nanosecond offsets from POSIX epoch. Both offsets are represented as Int64 values.

Parsing and formatting is based on a calendar time representation. Format strings are non-compatible and less powerful than for the other time packages. Parsing and formatting is based on an tokenizer that strictly converts the format string into a string of formatting tokens. Parsing and formatting is done by interpreting the format token string linearly in hand-rolled code, which is very efficient.

time-exts

This library doesn't support dates before POSIX epoch, even though it uses signed integral values to present the offset.

instance Bounded (UnixDateTimeNanos 'Gregorian) where

   -- 12:00:00.000000000 AM Thu Jan 01 1970.
   minBound = UnixDateTimeNanos 0 0

   -- 11:59:59.999999999 PM Fri Dec 31 9999.
   maxBound = UnixDateTimeNanos 253402300799 999999999

The library doesn't support formatting time values based on format strings.

It support parsing with a restricted set of format strings. Parsing is done via an attoparsec parser of type Parser (Parser (State (ParserState cal) ())). The outer parser parses the format strings and produces the parser for the time string.

Parsing performance is slightly better than with time.

Other Packages

unix-time provides high-level Haskell bindings to the system time functions, like strftime and strptime. We don't included it into the benchmarks because we require portability for our use case. In particular support GHCJS.

chronos is another time library. It's supposed to be efficient, but is less compatible with the other time libraries mentioned here. In particular it doesn't provide format strings, which is a feature that we required.

benchmarking add DiffTime date 0 1.0e-3/time
time 812.4 ns (757.9 ns .. 888.6 ns)
0.952 R² (0.924 R² .. 0.982 R²)
mean 810.3 ns (763.8 ns .. 867.8 ns)
std dev 167.6 ns (118.5 ns .. 229.8 ns)
variance introduced by outliers: 98% (severely inflated)
benchmarking add DiffTime date 0 1.0e-3/thyme
time 8.214 ns (8.096 ns .. 8.343 ns)
0.998 R² (0.998 R² .. 0.999 R²)
mean 8.236 ns (8.105 ns .. 8.413 ns)
std dev 516.0 ps (382.7 ps .. 809.4 ps)
variance introduced by outliers: 82% (severely inflated)
benchmarking add DiffTime date 0 1.0e-3/hourglass
time 202.5 ns (201.3 ns .. 204.2 ns)
0.999 R² (0.998 R² .. 1.000 R²)
mean 202.8 ns (201.0 ns .. 205.1 ns)
std dev 6.850 ns (4.710 ns .. 10.89 ns)
variance introduced by outliers: 51% (severely inflated)
benchmarking add DiffTime date 0 1.0e-3/time-exts
time 22.80 ns (22.45 ns .. 23.21 ns)
0.998 R² (0.996 R² .. 0.999 R²)
mean 22.53 ns (22.29 ns .. 22.96 ns)
std dev 1.020 ns (688.6 ps .. 1.519 ns)
variance introduced by outliers: 69% (severely inflated)
benchmarking add DiffTime date 0 1.0/time
time 731.9 ns (724.1 ns .. 741.4 ns)
0.997 R² (0.993 R² .. 0.999 R²)
mean 749.5 ns (737.1 ns .. 774.1 ns)
std dev 59.63 ns (35.79 ns .. 99.01 ns)
variance introduced by outliers: 84% (severely inflated)
benchmarking add DiffTime date 0 1.0/thyme
time 7.410 ns (7.334 ns .. 7.488 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 7.363 ns (7.329 ns .. 7.427 ns)
std dev 159.7 ps (114.1 ps .. 233.0 ps)
variance introduced by outliers: 35% (moderately inflated)
benchmarking add DiffTime date 0 1.0/hourglass
time 196.8 ns (194.1 ns .. 199.4 ns)
0.999 R² (0.998 R² .. 1.000 R²)
mean 196.6 ns (195.1 ns .. 199.6 ns)
std dev 6.893 ns (4.364 ns .. 11.29 ns)
variance introduced by outliers: 53% (severely inflated)
benchmarking add DiffTime date 0 1.0/time-exts
time 21.46 ns (21.32 ns .. 21.56 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 21.30 ns (21.22 ns .. 21.37 ns)
std dev 254.0 ps (208.6 ps .. 332.0 ps)
variance introduced by outliers: 13% (moderately inflated)
benchmarking add DiffTime date 0 10000.0/time
time 727.6 ns (724.3 ns .. 732.6 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 746.1 ns (738.2 ns .. 758.0 ns)
std dev 33.46 ns (25.18 ns .. 44.45 ns)
variance introduced by outliers: 62% (severely inflated)
benchmarking add DiffTime date 0 10000.0/thyme
time 7.349 ns (7.317 ns .. 7.395 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 7.416 ns (7.365 ns .. 7.492 ns)
std dev 210.3 ps (160.1 ps .. 283.7 ps)
variance introduced by outliers: 48% (moderately inflated)
benchmarking add DiffTime date 0 10000.0/hourglass
time 193.4 ns (191.0 ns .. 196.9 ns)
0.999 R² (0.998 R² .. 1.000 R²)
mean 193.2 ns (192.1 ns .. 194.8 ns)
std dev 4.769 ns (3.386 ns .. 6.710 ns)
variance introduced by outliers: 35% (moderately inflated)
benchmarking add DiffTime date 0 10000.0/time-exts
time 22.31 ns (21.66 ns .. 23.03 ns)
0.996 R² (0.993 R² .. 1.000 R²)
mean 21.95 ns (21.74 ns .. 22.27 ns)
std dev 902.0 ps (424.1 ps .. 1.378 ns)
variance introduced by outliers: 64% (severely inflated)
benchmarking add DiffTime date 0 1000000.0/time
time 742.0 ns (733.3 ns .. 750.3 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 734.3 ns (729.8 ns .. 740.0 ns)
std dev 16.55 ns (14.23 ns .. 20.71 ns)
variance introduced by outliers: 29% (moderately inflated)
benchmarking add DiffTime date 0 1000000.0/thyme
time 7.323 ns (7.291 ns .. 7.362 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 7.366 ns (7.324 ns .. 7.419 ns)
std dev 157.9 ps (125.1 ps .. 218.6 ps)
variance introduced by outliers: 34% (moderately inflated)
benchmarking add DiffTime date 0 1000000.0/hourglass
time 194.6 ns (193.9 ns .. 195.5 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 196.7 ns (195.3 ns .. 198.4 ns)
std dev 5.232 ns (3.888 ns .. 6.662 ns)
variance introduced by outliers: 39% (moderately inflated)
benchmarking add DiffTime date 0 1000000.0/time-exts
time 21.72 ns (21.54 ns .. 21.90 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 22.10 ns (21.89 ns .. 22.31 ns)
std dev 711.2 ps (601.7 ps .. 968.0 ps)
variance introduced by outliers: 53% (severely inflated)
benchmarking add DiffTime date 1 1.0e-3/time
time 428.0 ns (425.0 ns .. 432.4 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 433.3 ns (430.2 ns .. 436.7 ns)
std dev 10.82 ns (9.056 ns .. 12.99 ns)
variance introduced by outliers: 34% (moderately inflated)
benchmarking add DiffTime date 1 1.0e-3/thyme
time 7.458 ns (7.379 ns .. 7.572 ns)
0.998 R² (0.996 R² .. 1.000 R²)
mean 7.434 ns (7.365 ns .. 7.555 ns)
std dev 292.2 ps (178.8 ps .. 477.0 ps)
variance introduced by outliers: 64% (severely inflated)
benchmarking add DiffTime date 1 1.0e-3/hourglass
time 176.1 ns (172.5 ns .. 180.7 ns)
0.996 R² (0.992 R² .. 1.000 R²)
mean 175.2 ns (173.6 ns .. 179.6 ns)
std dev 8.496 ns (4.215 ns .. 15.72 ns)
variance introduced by outliers: 68% (severely inflated)
benchmarking add DiffTime date 1 1.0e-3/time-exts
time 22.21 ns (21.89 ns .. 22.61 ns)
0.998 R² (0.997 R² .. 0.999 R²)
mean 22.00 ns (21.76 ns .. 22.31 ns)
std dev 839.6 ps (605.4 ps .. 1.123 ns)
variance introduced by outliers: 61% (severely inflated)
benchmarking add DiffTime date 1 1.0/time
time 425.7 ns (420.0 ns .. 432.1 ns)
0.999 R² (0.998 R² .. 0.999 R²)
mean 424.4 ns (419.7 ns .. 430.4 ns)
std dev 17.87 ns (14.11 ns .. 23.55 ns)
variance introduced by outliers: 60% (severely inflated)
benchmarking add DiffTime date 1 1.0/thyme
time 8.143 ns (7.871 ns .. 8.501 ns)
0.994 R² (0.989 R² .. 0.999 R²)
mean 7.981 ns (7.874 ns .. 8.148 ns)
std dev 442.3 ps (273.5 ps .. 669.4 ps)
variance introduced by outliers: 78% (severely inflated)
benchmarking add DiffTime date 1 1.0/hourglass
time 178.5 ns (173.3 ns .. 183.1 ns)
0.997 R² (0.996 R² .. 0.999 R²)
mean 177.9 ns (175.5 ns .. 182.7 ns)
std dev 11.07 ns (6.592 ns .. 19.15 ns)
variance introduced by outliers: 78% (severely inflated)
benchmarking add DiffTime date 1 1.0/time-exts
time 22.05 ns (21.89 ns .. 22.26 ns)
0.999 R² (0.998 R² .. 1.000 R²)
mean 22.11 ns (21.96 ns .. 22.44 ns)
std dev 704.2 ps (468.9 ps .. 1.174 ns)
variance introduced by outliers: 52% (severely inflated)
benchmarking add DiffTime date 1 10000.0/time
time 468.0 ns (464.4 ns .. 473.2 ns)
0.999 R² (0.997 R² .. 1.000 R²)
mean 474.6 ns (469.7 ns .. 483.5 ns)
std dev 23.10 ns (11.15 ns .. 40.10 ns)
variance introduced by outliers: 67% (severely inflated)
benchmarking add DiffTime date 1 10000.0/thyme
time 8.042 ns (7.983 ns .. 8.123 ns)
0.999 R² (0.998 R² .. 1.000 R²)
mean 8.097 ns (8.036 ns .. 8.207 ns)
std dev 271.7 ps (191.1 ps .. 405.7 ps)
variance introduced by outliers: 56% (severely inflated)
benchmarking add DiffTime date 1 10000.0/hourglass
time 179.1 ns (174.8 ns .. 183.6 ns)
0.997 R² (0.995 R² .. 0.999 R²)
mean 175.9 ns (174.3 ns .. 178.9 ns)
std dev 6.911 ns (4.242 ns .. 10.66 ns)
variance introduced by outliers: 58% (severely inflated)
benchmarking add DiffTime date 1 10000.0/time-exts
time 23.42 ns (22.62 ns .. 24.46 ns)
0.991 R² (0.983 R² .. 0.997 R²)
mean 22.67 ns (22.30 ns .. 23.38 ns)
std dev 1.728 ns (1.051 ns .. 2.924 ns)
variance introduced by outliers: 86% (severely inflated)
benchmarking add DiffTime date 1 1000000.0/time
time 556.1 ns (550.2 ns .. 563.1 ns)
0.999 R² (0.998 R² .. 0.999 R²)
mean 549.3 ns (542.6 ns .. 558.2 ns)
std dev 25.45 ns (19.83 ns .. 32.22 ns)
variance introduced by outliers: 64% (severely inflated)
benchmarking add DiffTime date 1 1000000.0/thyme
time 8.342 ns (8.141 ns .. 8.648 ns)
0.993 R² (0.987 R² .. 0.999 R²)
mean 8.367 ns (8.204 ns .. 8.660 ns)
std dev 683.9 ps (392.2 ps .. 998.9 ps)
variance introduced by outliers: 89% (severely inflated)
benchmarking add DiffTime date 1 1000000.0/hourglass
time 206.3 ns (196.4 ns .. 217.0 ns)
0.987 R² (0.983 R² .. 0.993 R²)
mean 197.2 ns (191.4 ns .. 206.1 ns)
std dev 21.84 ns (17.88 ns .. 26.13 ns)
variance introduced by outliers: 92% (severely inflated)
benchmarking add DiffTime date 1 1000000.0/time-exts
time 24.72 ns (23.91 ns .. 25.93 ns)
0.988 R² (0.981 R² .. 0.995 R²)
mean 25.20 ns (24.46 ns .. 26.21 ns)
std dev 2.682 ns (2.048 ns .. 3.688 ns)
variance introduced by outliers: 93% (severely inflated)
benchmarking add DiffTime date 2 1.0e-3/time
time 699.6 ns (694.2 ns .. 706.4 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 697.3 ns (694.0 ns .. 701.2 ns)
std dev 12.67 ns (9.530 ns .. 16.63 ns)
variance introduced by outliers: 21% (moderately inflated)
benchmarking add DiffTime date 2 1.0e-3/thyme
time 7.619 ns (7.592 ns .. 7.660 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 7.761 ns (7.695 ns .. 7.867 ns)
std dev 278.7 ps (208.0 ps .. 369.6 ps)
variance introduced by outliers: 60% (severely inflated)
benchmarking add DiffTime date 2 1.0e-3/hourglass
time 200.2 ns (199.4 ns .. 201.1 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 200.0 ns (199.2 ns .. 200.9 ns)
std dev 2.957 ns (2.370 ns .. 3.886 ns)
variance introduced by outliers: 16% (moderately inflated)
benchmarking add DiffTime date 2 1.0e-3/time-exts
time 22.83 ns (22.58 ns .. 23.10 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 22.59 ns (22.46 ns .. 22.80 ns)
std dev 502.2 ps (387.3 ps .. 737.5 ps)
variance introduced by outliers: 34% (moderately inflated)
benchmarking add DiffTime date 2 1.0/time
time 698.5 ns (696.0 ns .. 700.7 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 703.2 ns (700.2 ns .. 707.3 ns)
std dev 12.13 ns (9.121 ns .. 16.78 ns)
variance introduced by outliers: 19% (moderately inflated)
benchmarking add DiffTime date 2 1.0/thyme
time 8.143 ns (8.118 ns .. 8.169 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 8.128 ns (8.104 ns .. 8.158 ns)
std dev 89.53 ps (67.88 ps .. 135.4 ps)
variance introduced by outliers: 12% (moderately inflated)
benchmarking add DiffTime date 2 1.0/hourglass
time 201.3 ns (200.8 ns .. 201.9 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 202.3 ns (201.4 ns .. 203.6 ns)
std dev 3.492 ns (2.609 ns .. 4.817 ns)
variance introduced by outliers: 21% (moderately inflated)
benchmarking add DiffTime date 2 1.0/time-exts
time 22.43 ns (22.37 ns .. 22.50 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 22.55 ns (22.46 ns .. 22.68 ns)
std dev 367.9 ps (272.0 ps .. 516.0 ps)
variance introduced by outliers: 22% (moderately inflated)
benchmarking add DiffTime date 2 10000.0/time
time 813.3 ns (740.7 ns .. 880.1 ns)
0.968 R² (0.957 R² .. 0.990 R²)
mean 745.8 ns (721.0 ns .. 788.4 ns)
std dev 102.3 ns (68.75 ns .. 144.9 ns)
variance introduced by outliers: 94% (severely inflated)
benchmarking add DiffTime date 2 10000.0/thyme
time 7.862 ns (7.767 ns .. 7.958 ns)
0.999 R² (0.997 R² .. 0.999 R²)
mean 7.733 ns (7.660 ns .. 7.837 ns)
std dev 305.7 ps (241.9 ps .. 479.3 ps)
variance introduced by outliers: 64% (severely inflated)
benchmarking add DiffTime date 2 10000.0/hourglass
time 187.7 ns (186.0 ns .. 189.9 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 190.7 ns (189.4 ns .. 192.4 ns)
std dev 4.975 ns (3.979 ns .. 6.484 ns)
variance introduced by outliers: 38% (moderately inflated)
benchmarking add DiffTime date 2 10000.0/time-exts
time 20.58 ns (20.44 ns .. 20.73 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 20.57 ns (20.47 ns .. 20.70 ns)
std dev 399.6 ps (328.3 ps .. 487.4 ps)
variance introduced by outliers: 29% (moderately inflated)
benchmarking add DiffTime date 2 1000000.0/time
time 659.5 ns (649.9 ns .. 671.5 ns)
0.998 R² (0.997 R² .. 0.999 R²)
mean 663.4 ns (655.1 ns .. 673.4 ns)
std dev 28.93 ns (21.98 ns .. 37.47 ns)
variance introduced by outliers: 61% (severely inflated)
benchmarking add DiffTime date 2 1000000.0/thyme
time 7.505 ns (7.468 ns .. 7.557 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 7.578 ns (7.521 ns .. 7.668 ns)
std dev 243.5 ps (151.1 ps .. 404.1 ps)
variance introduced by outliers: 54% (severely inflated)
benchmarking add DiffTime date 2 1000000.0/hourglass
time 183.5 ns (182.3 ns .. 185.0 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 185.0 ns (183.5 ns .. 187.2 ns)
std dev 5.815 ns (4.253 ns .. 8.967 ns)
variance introduced by outliers: 47% (moderately inflated)
benchmarking add DiffTime date 2 1000000.0/time-exts
time 20.51 ns (20.42 ns .. 20.61 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 20.54 ns (20.45 ns .. 20.66 ns)
std dev 359.0 ps (281.7 ps .. 472.7 ps)
variance introduced by outliers: 24% (moderately inflated)
benchmarking add DiffTime date 3 1.0e-3/time
time 661.7 ns (650.6 ns .. 672.9 ns)
0.998 R² (0.997 R² .. 0.999 R²)
mean 651.2 ns (645.6 ns .. 659.0 ns)
std dev 21.36 ns (15.88 ns .. 29.13 ns)
variance introduced by outliers: 47% (moderately inflated)
benchmarking add DiffTime date 3 1.0e-3/thyme
time 7.043 ns (7.000 ns .. 7.099 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 7.049 ns (7.013 ns .. 7.089 ns)
std dev 125.8 ps (106.2 ps .. 155.1 ps)
variance introduced by outliers: 27% (moderately inflated)
benchmarking add DiffTime date 3 1.0e-3/hourglass
time 194.9 ns (192.5 ns .. 197.2 ns)
0.999 R² (0.999 R² .. 0.999 R²)
mean 192.7 ns (191.1 ns .. 194.4 ns)
std dev 5.571 ns (4.422 ns .. 7.007 ns)
variance introduced by outliers: 43% (moderately inflated)
benchmarking add DiffTime date 3 1.0e-3/time-exts
time 20.57 ns (20.35 ns .. 20.82 ns)
0.999 R² (0.998 R² .. 0.999 R²)
mean 20.51 ns (20.35 ns .. 20.73 ns)
std dev 650.9 ps (506.9 ps .. 828.5 ps)
variance introduced by outliers: 52% (severely inflated)
benchmarking add DiffTime date 3 1.0/time
time 640.4 ns (637.2 ns .. 643.9 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 642.8 ns (638.6 ns .. 648.7 ns)
std dev 17.25 ns (11.96 ns .. 28.98 ns)
variance introduced by outliers: 37% (moderately inflated)
benchmarking add DiffTime date 3 1.0/thyme
time 7.674 ns (7.547 ns .. 7.852 ns)
0.997 R² (0.995 R² .. 0.999 R²)
mean 7.720 ns (7.616 ns .. 7.847 ns)
std dev 394.5 ps (308.0 ps .. 518.7 ps)
variance introduced by outliers: 75% (severely inflated)
benchmarking add DiffTime date 3 1.0/hourglass
time 190.1 ns (188.8 ns .. 191.2 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 189.7 ns (188.6 ns .. 191.9 ns)
std dev 4.739 ns (3.032 ns .. 8.617 ns)
variance introduced by outliers: 36% (moderately inflated)
benchmarking add DiffTime date 3 1.0/time-exts
time 20.70 ns (20.42 ns .. 20.92 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 20.43 ns (20.27 ns .. 20.67 ns)
std dev 635.0 ps (486.4 ps .. 884.0 ps)
variance introduced by outliers: 51% (severely inflated)
benchmarking add DiffTime date 3 10000.0/time
time 639.9 ns (633.5 ns .. 646.8 ns)
0.998 R² (0.998 R² .. 0.999 R²)
mean 640.7 ns (635.1 ns .. 649.0 ns)
std dev 22.98 ns (17.55 ns .. 29.74 ns)
variance introduced by outliers: 51% (severely inflated)
benchmarking add DiffTime date 3 10000.0/thyme
time 7.421 ns (7.372 ns .. 7.459 ns)
1.000 R² (1.000 R² .. 1.000 R²)
mean 7.425 ns (7.379 ns .. 7.528 ns)
std dev 223.2 ps (108.5 ps .. 421.4 ps)
variance introduced by outliers: 51% (severely inflated)
benchmarking add DiffTime date 3 10000.0/hourglass
time 199.3 ns (194.0 ns .. 204.5 ns)
0.996 R² (0.993 R² .. 0.998 R²)
mean 196.6 ns (194.0 ns .. 200.5 ns)
std dev 11.16 ns (8.343 ns .. 16.27 ns)
variance introduced by outliers: 75% (severely inflated)
benchmarking add DiffTime date 3 10000.0/time-exts
time 20.18 ns (20.04 ns .. 20.35 ns)
0.999 R² (0.999 R² .. 1.000 R²)
mean 20.20 ns (20.08 ns .. 20.36 ns)
std dev 491.5 ps (389.7 ps .. 608.8 ps)
variance introduced by outliers: 39% (moderately inflated)
benchmarking add DiffTime date 3 1000000.0/time
time 677.4 ns (659.3 ns .. 691.7 ns)
0.996 R² (0.994 R² .. 0.998 R²)
mean 651.5 ns (643.2 ns .. 662.9 ns)
std dev 33.33 ns (25.57 ns .. 45.56 ns)
variance introduced by outliers: 68% (severely inflated)
benchmarking add DiffTime date 3 1000000.0/thyme
time 7.779 ns (7.681 ns .. 7.911 ns)
0.999 R² (0.998 R² .. 0.999 R²)
mean 7.913 ns (7.829 ns .. 7.999 ns)
std dev 273.0 ps (235.7 ps .. 328.8 ps)
variance introduced by outliers: 58% (severely inflated)
benchmarking add DiffTime date 3 1000000.0/hourglass
time 203.3 ns (201.0 ns .. 205.8 ns)
0.999 R² (0.999 R² .. 0.999 R²)
mean 204.9 ns (203.0 ns .. 206.8 ns)
std dev 6.272 ns (5.244 ns .. 7.873 ns)
variance introduced by outliers: 46% (moderately inflated)
benchmarking add DiffTime date 3 1000000.0/time-exts
time 20.21 ns (20.11 ns .. 20.36 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 20.44 ns (20.32 ns .. 20.57 ns)
std dev 465.1 ps (382.4 ps .. 588.9 ps)
variance introduced by outliers: 35% (moderately inflated)
benchmarking format time date 0/time
time 8.272 μs (8.064 μs .. 8.649 μs)
0.971 R² (0.940 R² .. 0.993 R²)
mean 8.920 μs (8.468 μs .. 9.747 μs)
std dev 1.955 μs (1.045 μs .. 3.066 μs)
variance introduced by outliers: 97% (severely inflated)
benchmarking format time date 0/thyme
time 2.440 μs (2.375 μs .. 2.532 μs)
0.996 R² (0.992 R² .. 1.000 R²)
mean 2.396 μs (2.380 μs .. 2.440 μs)
std dev 81.61 ns (42.15 ns .. 153.5 ns)
variance introduced by outliers: 45% (moderately inflated)
benchmarking format time date 0/hourglass
time 1.446 μs (1.403 μs .. 1.501 μs)
0.993 R² (0.988 R² .. 0.997 R²)
mean 1.440 μs (1.414 μs .. 1.475 μs)
std dev 95.11 ns (75.35 ns .. 140.3 ns)
variance introduced by outliers: 77% (severely inflated)
benchmarking format time date 0/hourglass/dynamic
time 1.349 μs (1.340 μs .. 1.360 μs)
0.999 R² (0.998 R² .. 1.000 R²)
mean 1.369 μs (1.357 μs .. 1.386 μs)
std dev 47.73 ns (38.97 ns .. 59.19 ns)
variance introduced by outliers: 48% (moderately inflated)
benchmarking format time date 1/time
time 6.113 μs (5.979 μs .. 6.228 μs)
0.998 R² (0.997 R² .. 1.000 R²)
mean 6.029 μs (5.987 μs .. 6.084 μs)
std dev 159.7 ns (112.6 ns .. 228.8 ns)
variance introduced by outliers: 31% (moderately inflated)
benchmarking format time date 1/thyme
time 2.673 μs (2.554 μs .. 2.793 μs)
0.990 R² (0.983 R² .. 0.998 R²)
mean 2.531 μs (2.479 μs .. 2.611 μs)
std dev 217.4 ns (153.5 ns .. 354.0 ns)
variance introduced by outliers: 84% (severely inflated)
benchmarking format time date 1/hourglass
time 1.305 μs (1.290 μs .. 1.323 μs)
0.997 R² (0.996 R² .. 0.998 R²)
mean 1.373 μs (1.344 μs .. 1.401 μs)
std dev 97.46 ns (82.57 ns .. 124.5 ns)
variance introduced by outliers: 80% (severely inflated)
benchmarking format time date 1/hourglass/dynamic
time 1.357 μs (1.331 μs .. 1.388 μs)
0.995 R² (0.991 R² .. 0.998 R²)
mean 1.359 μs (1.331 μs .. 1.399 μs)
std dev 111.6 ns (79.01 ns .. 161.2 ns)
variance introduced by outliers: 84% (severely inflated)
benchmarking format time date 2/time
time 8.562 μs (8.169 μs .. 9.048 μs)
0.984 R² (0.977 R² .. 0.994 R²)
mean 8.982 μs (8.728 μs .. 9.322 μs)
std dev 970.2 ns (763.2 ns .. 1.203 μs)
variance introduced by outliers: 88% (severely inflated)
benchmarking format time date 2/thyme
time 2.384 μs (2.373 μs .. 2.397 μs)
1.000 R² (1.000 R² .. 1.000 R²)
mean 2.399 μs (2.387 μs .. 2.413 μs)
std dev 44.77 ns (35.66 ns .. 58.90 ns)
variance introduced by outliers: 20% (moderately inflated)
benchmarking format time date 2/hourglass
time 1.352 μs (1.336 μs .. 1.371 μs)
0.999 R² (0.997 R² .. 0.999 R²)
mean 1.359 μs (1.346 μs .. 1.374 μs)
std dev 48.99 ns (37.78 ns .. 72.91 ns)
variance introduced by outliers: 50% (moderately inflated)
benchmarking format time date 2/hourglass/dynamic
time 1.422 μs (1.391 μs .. 1.458 μs)
0.996 R² (0.995 R² .. 0.998 R²)
mean 1.470 μs (1.443 μs .. 1.507 μs)
std dev 109.4 ns (80.24 ns .. 168.7 ns)
variance introduced by outliers: 81% (severely inflated)
benchmarking format time date 3/time
time 7.705 μs (7.658 μs .. 7.765 μs)
0.999 R² (0.998 R² .. 1.000 R²)
mean 7.800 μs (7.716 μs .. 7.913 μs)
std dev 307.6 ns (228.4 ns .. 418.8 ns)
variance introduced by outliers: 49% (moderately inflated)
benchmarking format time date 3/thyme
time 2.375 μs (2.350 μs .. 2.401 μs)
0.999 R² (0.999 R² .. 1.000 R²)
mean 2.351 μs (2.343 μs .. 2.366 μs)
std dev 35.57 ns (23.70 ns .. 61.85 ns)
variance introduced by outliers: 14% (moderately inflated)
benchmarking format time date 3/hourglass
time 1.382 μs (1.342 μs .. 1.416 μs)
0.997 R² (0.996 R² .. 0.999 R²)
mean 1.354 μs (1.341 μs .. 1.372 μs)
std dev 50.76 ns (37.45 ns .. 65.04 ns)
variance introduced by outliers: 52% (severely inflated)
benchmarking format time date 3/hourglass/dynamic
time 1.491 μs (1.436 μs .. 1.532 μs)
0.994 R² (0.992 R² .. 0.996 R²)
mean 1.444 μs (1.418 μs .. 1.471 μs)
std dev 85.69 ns (70.73 ns .. 107.4 ns)
variance introduced by outliers: 73% (severely inflated)
benchmarking getCurrentTime/time
time 76.26 ns (75.83 ns .. 76.79 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 76.95 ns (76.19 ns .. 78.29 ns)
std dev 3.291 ns (1.947 ns .. 5.065 ns)
variance introduced by outliers: 64% (severely inflated)
benchmarking getCurrentTime/thyme
time 42.26 ns (41.35 ns .. 43.15 ns)
0.998 R² (0.997 R² .. 1.000 R²)
mean 41.66 ns (41.34 ns .. 42.12 ns)
std dev 1.201 ns (812.4 ps .. 1.885 ns)
variance introduced by outliers: 46% (moderately inflated)
benchmarking getCurrentTime/hourglass
time 4.272 μs (4.215 μs .. 4.345 μs)
0.998 R² (0.997 R² .. 0.999 R²)
mean 4.329 μs (4.275 μs .. 4.420 μs)
std dev 230.5 ns (171.9 ns .. 314.2 ns)
variance introduced by outliers: 65% (severely inflated)
benchmarking getCurrentTime/time-exts
time 164.6 ns (163.6 ns .. 165.6 ns)
1.000 R² (0.999 R² .. 1.000 R²)
mean 164.2 ns (163.4 ns .. 165.5 ns)
std dev 3.412 ns (2.441 ns .. 5.513 ns)
variance introduced by outliers: 28% (moderately inflated)
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UnicodeSyntax #-}
-- |
-- Module: Main
-- Copyright: Copyright © 2018 Kadena LLC.
-- License: MIT
-- Maintainer: Lars Kuhtz <[email protected]>
-- Stability: experimental
--
-- Compile with:
--
-- @
-- ghc -O2 -threaded -package time-1.8.0.2 -package thyme-0.3.5.5 Main.hs
-- @
--
module Main
( main
) where
import Criterion
import Criterion.Main
import Data.Maybe
import qualified Data.Text as T
import qualified System.Locale as OL
-- Time packages
import qualified Data.Time as TI
import qualified Data.Thyme.Clock as TY
import qualified Data.Thyme.Time.Core as TY
import qualified Data.Hourglass as HG
import qualified System.Hourglass as HG
import qualified Data.Time.Exts.Base as TE
import qualified Data.Time.Exts.UTC as TE
defFormat ∷ String
defFormat = "%Y-%m-%dT%H:%M:%S%Q%z"
hgFormat ∷ String
hgFormat = "YYYY-MM-DDTH:MI:S.p6TZHM"
timeStrs ∷ [(String, String)]
timeStrs =
[ ("date 0", "1234-07-31T13:23:00.203719+0000")
, ("date 1", "1970-01-01T00:00:00.000000+0000")
, ("date 2", "2018-07-31T13:23:00.203719+0900")
, ("date 3", "3123-07-31T13:23:00.203719-1100")
]
withTime
∷ String
→ IO (TI.UTCTime, TY.UTCTime, HG.DateTime, TE.UTCDateTimeNanos 'TE.Gregorian)
withTime s = do
!ti ← TI.parseTimeM False TI.defaultTimeLocale defFormat s
let !ty = TY.toThyme ti
let !hg = fromJust $ HG.timeParse hgFormat s
let !te = either error id $ if s /= "1234-07-31T13:23:00.203719+0000"
then TE.parseUTCDateTimeNanos OL.defaultTimeLocale (T.pack defFormat) (T.pack s)
else TE.parseUTCDateTimeNanos OL.defaultTimeLocale (T.pack defFormat) "1970-01-01T00:00:00.000000+0000"
-- time-exts doesn't support dates that are before POSIX epoch
return (ti, ty, hg, te)
main ∷ IO ()
main = defaultMain $
[ bgroup "getCurrentTime"
[ bench "time" $ nfIO TI.getCurrentTime
, bench "thyme" $ nfIO TY.getCurrentTime
, bench "hourglass" $ nfIO HG.timeCurrent
, bench "time-exts" $ nfIO TE.getCurrentUTCDateTimeNanos
]
]
++
(formatBench <$> timeStrs)
++
(parseBench <$> timeStrs)
++
(addUTCTimeBench <$> timeStrs <*> [0.001, 1, 10000, 1000000])
formatBench ∷ (String, String) → Benchmark
formatBench (l,s) = env (withTime s) $ \ ~(ti, ty, hg, _te) → bgroup ("format time " ++ l)
[ bench "time" $ nf (TI.formatTime TI.defaultTimeLocale defFormat) ti
, bench "thyme" $ nf (TY.formatTime OL.defaultTimeLocale defFormat) ty
, bench "hourglass" $ nf (HG.timePrint hgFormat) hg
, bench "hourglass/dynamic" $ nf (uncurry HG.timePrint) (hgFormat, hg)
-- parses the format string on the fly
]
parseBench ∷ (String, String) → Benchmark
parseBench (l,s) = bgroup ("parse time " ++ l) $
[ bench "time" $ nf (check @TI.UTCTime . TI.parseTimeM True TI.defaultTimeLocale defFormat) s
, bench "thyme" $ nf (check @TY.UTCTime . TY.parseTime OL.defaultTimeLocale defFormat) s
, bench "hourglass" $ nf (check @HG.DateTime . HG.timeParse hgFormat) s
, bench "hourglass/dynamic" $ nf (check @HG.DateTime . uncurry HG.timeParse) (hgFormat, s)
]
<>
[ bench "time-exts"
$ nf (check' . TE.parseUTCDateTimeNanos OL.defaultTimeLocale (T.pack defFormat)) (T.pack s)
| l /= "date 0"
]
where
check ∷ Maybe a → a
check = fromMaybe (error "parse failure")
check' ∷ Either String a → a
check' = either error id
addUTCTimeBench ∷ (String, String) → Double → Benchmark
addUTCTimeBench (l, s) d = env (withTime s) $ \ ~(ti, ty, hg, te) → bgroup ("add DiffTime " ++ l ++ " " ++ show d)
[ bench "time" $ nf (TI.addUTCTime (realToFrac d)) ti
, bench "thyme" $ nf (TY.addUTCTime (TY.fromSeconds d)) ty
, bench "hourglass" $ nf (`HG.timeAdd` (HG.NanoSeconds $ round $ d * 1000000000)) hg
, bench "time-exts" $ nf (`TE.plus` (TE.Nanos $ round $ d * 1000000000)) te
]
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment