Skip to content

Instantly share code, notes, and snippets.

@int-index
Last active February 12, 2019 23:27
Show Gist options
  • Save int-index/38af0c5dd801088dc1de59eca4e55df4 to your computer and use it in GitHub Desktop.
Save int-index/38af0c5dd801088dc1de59eca4e55df4 to your computer and use it in GitHub Desktop.
Arrows.hs Measurements
{-# LANGUAGE Arrows #-}
import Control.Arrow (returnA)
f :: () -> ()
f =
proc () ->
let _ = () in
let _ = () in
let _ = () in
let _ = () in
-- and then on line 284168
returnA -< ()
Command:
$ inplace/bin/ghc-stage2 -ddump-timings ~/Arrows.hs
Measurements:
master
Parser [Main]: alloc=9560778976 time=7956.168
Parser [Main]: alloc=9560778976 time=7911.255
Parser [Main]: alloc=9560778976 time=7978.155
Parser [Main]: alloc=9560778976 time=8072.056
Parser [Main]: alloc=9560778976 time=7867.061
wip/exp-pat-frame (deep embedding)
Parser [Main]: alloc=9574418648 time=8050.242
Parser [Main]: alloc=9574418648 time=7928.873
Parser [Main]: alloc=9574418648 time=7896.294
Parser [Main]: alloc=9574418648 time=7917.393
Parser [Main]: alloc=9574418648 time=7840.901
wip/exp-cmd-frame (shallow embedding, without --coerce)
Parser [Main]: alloc=9899586040 time=8769.317
Parser [Main]: alloc=9899586040 time=8843.270
Parser [Main]: alloc=9899586040 time=8698.141
Parser [Main]: alloc=9899586040 time=8757.309
Parser [Main]: alloc=9899586040 time=8771.368
wip/exp-cmd-frame (shallow embedding, with --coerce)
Parser [Main]: alloc=9706356832 time=7963.211
Parser [Main]: alloc=9706356832 time=8002.884
Parser [Main]: alloc=9706356832 time=8085.704
Parser [Main]: alloc=9706356832 time=8042.423
Parser [Main]: alloc=9706356832 time=8007.699
@int-index
Copy link
Author

NB. Thermal throttling of my CPU seemed to have an effect on the execution time, changing the results by up to 1500 units. The performance numbers were much worse right after a full rebuild (in the ballpark of 9500).

When interleaving tests for master, wip/exp-pat-frame (deep embedding), and wip/exp-cmd-frame (shallow embedding (with --coerce), I observe very similar numbers:

  1. master: Parser [Main]: alloc=9560778976 time=7973.300
  2. wip/exp-pat-frame: Parser [Main]: alloc=9574418648 time=7878.008
  3. wip/exp-cmd-frame: Parser [Main]: alloc=9706356832 time=7957.351

It is therefore safe to conclude that neither of the approaches has any significant impact on parsing performance. Omitting --coerce has some negative performance impact, about 10%.

@int-index
Copy link
Author

int-index commented Feb 12, 2019

Using a GADT instead of a CPS encoding in the shallow embedding had no effect: time spent is still approximately equal to that in master:

  1. master: Parser [Main]: alloc=9560778976 time=8090.421
  2. wip/exp-pat-frame: Parser [Main]: alloc=9574418648 time=7921.118
  3. wip/exp-cmd-frame: Parser [Main]: alloc=9679077216 time=8006.478

Allocations are apparently slightly reduced.

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