Skip to content

head not O(1) #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jacereda opened this issue Nov 6, 2016 · 1 comment
Closed

head not O(1) #76

jacereda opened this issue Nov 6, 2016 · 1 comment

Comments

@jacereda
Copy link
Contributor

jacereda commented Nov 6, 2016

Looks like head isn't O(1), at least on node v4.4.7.

I measured with purescript-benchotron as follows:

benchHead :: Benchmark
benchHead = mkBenchmark
  { slug: "head"
  , title: "Head of a structure"
  , sizes: (1 .. 8) <#> (_ * 150)
  , sizeInterpretation: "Number of elements in the structure"
  , inputsPerSize: 1
  , gen: randomArray
  , functions: [ benchFn "Array" A.head
               , benchFn "Array'" (_ `A.index` 0)
               ]
  }
@hdgarrood
Copy link
Contributor

Ah, right, yeah, because it uses uncons, which does xs.slice(1). In fact looking through the code in src/Data/Array.purs I suspect most of the other uses of uncons or uncons' could probably be reworked for better performance.

jacereda added a commit to jacereda/purescript-arrays that referenced this issue Nov 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants