[Haskell-cafe] Seven ways to store 16 bytes

Felipe Lessa felipe.lessa at gmail.com
Tue Jan 5 20:25:38 EST 2010


On Tue, Jan 05, 2010 at 04:40:55PM -0800, Bryan O'Sullivan wrote:
> You've got an extra level of indirection there due to the use of data
> instead of newtype, so you're paying an additional boxing penalty for
> everything except your first case. Are you compiling with
> -funbox-strict-fields?

I've changed those data's to newtype's but using words still
seems better, unless mapping and folding over bytes is more
important.  In that case maybe storing the bytes separately might
be better.  Maybe a more complex/realistic benchmark?

I've also rerun the benchmark in a x86-32 chroot.  In this
environment Word32 seems to win over Word64.  But, who cares
about 32 bits anyway? ;)

I'm attaching the source code and the summary results.
Everything was compiled with 'ghc -fforce-recomp -O3'.

--
Felipe.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SixteenBytes.hs
Type: text/x-haskell
Size: 12560 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100105/e041d985/SixteenBytes.bin
-------------- next part --------------
equal-itself/bytes                 154.48 ns
equal-itself/words                  73.11 ns
equal-itself/words64                89.19 ns
equal-itself/list                  455.64 ns
equal-itself/byteString            129.09 ns
equal-itself/array                 214.65 ns
equal-itself/uArray                134.84 ns
equal-itself/vector                575.81 ns

equal-same/bytes                   153.40 ns
equal-same/words                    74.95 ns
equal-same/words64                  84.43 ns
equal-same/list                    464.60 ns
equal-same/byteString              157.38 ns
equal-same/array                   190.70 ns
equal-same/uArray                  136.00 ns
equal-same/vector                  584.04 ns

equal-differ/bytes                  78.01 ns
equal-differ/words                  62.94 ns
equal-differ/words64                69.21 ns
equal-differ/list                   82.36 ns
equal-differ/byteString            155.94 ns
equal-differ/array                  76.39 ns
equal-differ/uArray                 83.74 ns
equal-differ/vector                545.27 ns

compare-same/bytes                 139.47 ns
compare-same/words                  76.23 ns
compare-same/words64                90.45 ns
compare-same/list                  470.13 ns
compare-same/byteString             83.46 ns
compare-same/array                 458.69 ns
compare-same/uArray                413.76 ns
compare-same/vector                538.52 ns

compare-differ/bytes                79.67 ns
compare-differ/words                70.50 ns
compare-differ/words64              84.21 ns
compare-differ/list                 83.46 ns
compare-differ/byteString           83.83 ns
compare-differ/array                93.82 ns
compare-differ/uArray               94.27 ns
compare-differ/vector              499.22 ns

toList-and-sum/bytes               556.38 ns
toList-and-sum/words               895.83 ns
toList-and-sum/words64               1.15 us
toList-and-sum/list                539.67 ns
toList-and-sum/byteString          706.27 ns
toList-and-sum/array               922.25 ns
toList-and-sum/uArray              807.74 ns
toList-and-sum/vector              871.35 ns

map-and-sum/bytes                  418.83 ns
map-and-sum/words                  865.35 ns
map-and-sum/words64                  1.21 us
map-and-sum/list                   547.88 ns
map-and-sum/byteString             554.30 ns
map-and-sum/array                  672.47 ns
map-and-sum/uArray                 590.94 ns
map-and-sum/vector                 596.50 ns

fold-and-sum/bytes                 481.02 ns
fold-and-sum/words                 639.72 ns
fold-and-sum/words64               865.86 ns
fold-and-sum/list                  304.06 ns
fold-and-sum/byteString            341.16 ns
fold-and-sum/array                 632.82 ns
fold-and-sum/uArray                522.96 ns
fold-and-sum/vector                339.46 ns

fromList-and-eq/bytes              790.68 ns
fromList-and-eq/words              666.65 ns
fromList-and-eq/words64            994.36 ns
fromList-and-eq/list               778.35 ns
fromList-and-eq/byteString         857.47 ns
fromList-and-eq/array              933.95 ns
fromList-and-eq/uArray               3.90 us
fromList-and-eq/vector               1.40 us

build-and-eq/bytes                 568.29 ns
build-and-eq/words                 510.61 ns
build-and-eq/words64               890.87 ns
build-and-eq/list                    1.03 us
build-and-eq/byteString            824.19 ns
build-and-eq/array                 960.80 ns
build-and-eq/uArray                  3.79 us
build-and-eq/vector                  1.28 us

unfold-and-eq/bytes                624.53 ns
unfold-and-eq/words                565.21 ns
unfold-and-eq/words64              875.83 ns
unfold-and-eq/list                   1.21 us
unfold-and-eq/byteString             1.35 us
unfold-and-eq/array                  1.09 us
unfold-and-eq/uArray                 3.88 us
unfold-and-eq/vector                 1.19 us
-------------- next part --------------
equal-itself/bytes                 149.75 ns
equal-itself/words                  76.60 ns
equal-itself/words64                63.62 ns
equal-itself/list                  516.47 ns
equal-itself/byteString            141.86 ns
equal-itself/array                 192.89 ns
equal-itself/uArray                145.88 ns
equal-itself/vector                467.59 ns

equal-same/bytes                   152.78 ns
equal-same/words                    88.18 ns
equal-same/words64                  68.02 ns
equal-same/list                    523.40 ns
equal-same/byteString              174.43 ns
equal-same/array                   192.97 ns
equal-same/uArray                  123.93 ns
equal-same/vector                  477.57 ns

equal-differ/bytes                  85.94 ns
equal-differ/words                  65.51 ns
equal-differ/words64                63.60 ns
equal-differ/list                   89.86 ns
equal-differ/byteString            174.97 ns
equal-differ/array                  81.49 ns
equal-differ/uArray                 81.89 ns
equal-differ/vector                467.45 ns

compare-same/bytes                 155.65 ns
compare-same/words                  83.35 ns
compare-same/words64                70.42 ns
compare-same/list                  475.55 ns
compare-same/byteString             95.35 ns
compare-same/array                 736.59 ns
compare-same/uArray                431.40 ns
compare-same/vector                513.61 ns

compare-differ/bytes                90.90 ns
compare-differ/words                79.41 ns
compare-differ/words64              93.59 ns
compare-differ/list                136.76 ns
compare-differ/byteString           94.89 ns
compare-differ/array               105.18 ns
compare-differ/uArray              103.92 ns
compare-differ/vector              610.92 ns

toList-and-sum/bytes               649.31 ns
toList-and-sum/words               959.82 ns
toList-and-sum/words64               1.02 us
toList-and-sum/list                605.01 ns
toList-and-sum/byteString          759.76 ns
toList-and-sum/array                 1.11 us
toList-and-sum/uArray              942.17 ns
toList-and-sum/vector              971.62 ns

map-and-sum/bytes                  512.01 ns
map-and-sum/words                    1.23 us
map-and-sum/words64                  1.25 us
map-and-sum/list                   693.42 ns
map-and-sum/byteString             586.06 ns
map-and-sum/array                  838.49 ns
map-and-sum/uArray                 707.18 ns
map-and-sum/vector                 777.43 ns

fold-and-sum/bytes                 647.92 ns
fold-and-sum/words                 890.31 ns
fold-and-sum/words64               910.96 ns
fold-and-sum/list                  301.64 ns
fold-and-sum/byteString            399.00 ns
fold-and-sum/array                 696.64 ns
fold-and-sum/uArray                564.33 ns
fold-and-sum/vector                375.66 ns

fromList-and-eq/bytes                1.01 us
fromList-and-eq/words              819.08 ns
fromList-and-eq/words64            822.43 ns
fromList-and-eq/list                 1.00 us
fromList-and-eq/byteString           1.01 us
fromList-and-eq/array              922.43 ns
fromList-and-eq/uArray               4.49 us
fromList-and-eq/vector               1.23 us

build-and-eq/bytes                 609.08 ns
build-and-eq/words                 532.92 ns
build-and-eq/words64               498.30 ns
build-and-eq/list                    1.16 us
build-and-eq/byteString            896.24 ns
build-and-eq/array                 866.45 ns
build-and-eq/uArray                 17.39 us
build-and-eq/vector                  1.19 us

unfold-and-eq/bytes                807.60 ns
unfold-and-eq/words                603.23 ns
unfold-and-eq/words64              645.94 ns
unfold-and-eq/list                   1.38 us
unfold-and-eq/byteString             1.46 us
unfold-and-eq/array                  1.08 us
unfold-and-eq/uArray                 4.44 us
unfold-and-eq/vector                 1.11 us


More information about the Haskell-Cafe mailing list