I still haven't found a way to make blogger respect whitespace, so yet again I present unformatted code.
I now have everything up and running bug free on the new api except Adrian's avl trees (which I've saved for last). Heres a simple benchmark running ListMap against Data.Map. Bear in mind that as I don't have the avl trees yet the inner map used for list map is the association list from my reference implementation - not the fastest data structure in the world.
import qualified Data.Map as M
import qualified Data.GMap as G
import Data.GMap.ListMap
import Data.GMap.AssocList
import System.IO
import System.IO.Unsafe
import Data.Maybe
dict = lines $ unsafePerformIO $ readFile "/usr/share/dict/words"
test =
let mp = {-# SCC "Map.fromList" #-} M.fromAscList $ zip dict $ repeat ()
in all isJust $ map (\w -> {-# SCC "Map.lookup" #-} M.lookup w mp) dict
testG =
let mp :: ListMap (SList Char) Char ()
mp = {-# SCC "GMap.fromAssocs" #-} G.fromAssocsAsc $ zip dict $ repeat ()
in all isJust $ map (\w -> {-# SCC "GMap.lookup" #-} G.lookup w mp) dict
main = do
print $ test
print $ testG
And the results:
COST CENTRE MODULE %time %alloc
CAF Main 68.9 91.7
Map.lookup Main 14.8 0.3
GMap.lookup Main 14.8 1.9
Map.fromList Main 1.6 4.6
GMap.fromAssocs Main 0.0 1.6
So, not unsurprisingly, ListMap is already faster for trie friendly tests. Once I've updated the avl trees there should be no competition.
Wednesday, 30 July 2008
Subscribe to:
Post Comments (Atom)
1 comments:
re formatting: <pre> tags work fine in blogger posts. If you want syntax highlighting the output of hscolour -css works well, if you set up appropriate styles in your template.
Post a Comment