Skip to content

decimal is quadratic #217

@phadej

Description

@phadej
Prelude Data.Attoparsec.Text Data.Text> fmap signum (parseOnly decimal (Data.Text.replicate 100000 "9") :: Either String Integer)
Right 1
(0.32 secs, 4,286,165,576 bytes)
Prelude Data.Attoparsec.Text Data.Text> fmap signum (parseOnly decimal (Data.Text.replicate 200000 "9") :: Either String Integer)
Right 1
(1.19 secs, 17,092,657,496 bytes)
Prelude Data.Attoparsec.Text Data.Text> fmap signum (parseOnly decimal (Data.Text.replicate 400000 "9") :: Either String Integer)
Right 1
(4.83 secs, 68,266,651,512 bytes)
Prelude Data.Attoparsec.Text Data.Text> fmap signum (parseOnly decimal (Data.Text.replicate 800000 "9") :: Either String Integer)
Right 1
(18.86 secs, 272,858,846,272 bytes)

when doubling the size of input the time quadruples.

Tested using cabal build --write-ghc-environment-files=always, and then loading the library into repl. So the important parts are not interpreted.

In comparison, read is almost instant

Prelude Data.Attoparsec.Text Data.Text> signum (read (Prelude.replicate 800000 '9') :: Integer)
1
(0.21 secs, 333,060,168 bytes)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions