Skip to content
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

Speed up toLower #460

Merged
merged 3 commits into from
Aug 2, 2022
Merged

Speed up toLower #460

merged 3 commits into from
Aug 2, 2022

Conversation

Bodigrim
Copy link
Contributor

Fixes #459. CC @noughtmare

@phadej
Copy link
Contributor

phadej commented Jul 26, 2022

What about toCaseFold, toUpper and toTitle?

@Bodigrim
Copy link
Contributor Author

Should be improved in the same way, this is just a quick draft.

@Bodigrim
Copy link
Contributor Author

Benchmarks:

tiny
  toLower
    Text:     OK (1.46s)
      42.6 ns ± 3.8 ns, 74% faster than baseline
    LazyText: OK (3.70s)
      54.6 ns ± 1.6 ns, 74% faster than baseline
  toUpper
    Text:     OK (5.90s)
      43.5 ns ± 2.5 ns, 75% faster than baseline
    LazyText: OK (1.90s)
      56.1 ns ± 4.5 ns, 75% faster than baseline
ascii-small
  toLower
    Text:     OK (6.97s)
      212  μs ±  12 μs, 88% faster than baseline
    LazyText: OK (1.82s)
      216  μs ±  17 μs, 89% faster than baseline
  toUpper
    Text:     OK (2.13s)
      258  μs ±  25 μs, 89% faster than baseline
    LazyText: OK (4.40s)
      264  μs ±  10 μs, 90% faster than baseline
ascii
  toLower
    Text:     OK (1.69s)
      182  ms ±  17 ms, 90% faster than baseline
    LazyText: OK (15.15s)
      233  ms ± 6.9 ms, 87% faster than baseline
  toUpper
    Text:     OK (3.79s)
      220  ms ±  17 ms, 90% faster than baseline
    LazyText: OK (4.33s)
      264  ms ±  21 ms, 89% faster than baseline
english
  toLower
    Text:     OK (6.17s)
      11.7 ms ± 227 μs, 90% faster than baseline
    LazyText: OK (3.13s)
      12.0 ms ± 537 μs, 90% faster than baseline
  toUpper
    Text:     OK (2.05s)
      15.7 ms ± 1.4 ms, 89% faster than baseline
    LazyText: OK (8.14s)
      15.5 ms ± 690 μs, 90% faster than baseline
russian
  toLower
    Text:     OK (2.22s)
      67.9 μs ± 6.3 μs, 66% faster than baseline
    LazyText: OK (2.13s)
      62.9 μs ± 4.0 μs, 71% faster than baseline
  toUpper
    Text:     OK (2.22s)
      136  μs ±  13 μs, 44% faster than baseline
    LazyText: OK (2.24s)
      135  μs ± 6.9 μs, 50% faster than baseline
japanese
  toLower
    Text:     OK (2.90s)
      43.2 μs ± 2.5 μs, 66% faster than baseline
    LazyText: OK (3.01s)
      44.7 μs ± 3.0 μs, 67% faster than baseline
  toUpper
    Text:     OK (1.49s)
      44.1 μs ± 4.0 μs, 64% faster than baseline
    LazyText: OK (2.96s)
      45.1 μs ± 2.4 μs, 66% faster than baseline

@Bodigrim Bodigrim marked this pull request as ready for review July 26, 2022 22:34
@noughtmare
Copy link
Contributor

I can confirm that this also makes the Haskell code almost as fast as Python's standard library:

Benchmark 1: haskell/simple-exe <kjvbible.txt
  Time (mean ± σ):      80.4 ms ±   3.2 ms    [User: 64.2 ms, System: 7.0 ms]
  Range (min … max):    71.7 ms …  89.2 ms    35 runs

Benchmark 1: python3 simple.py <kjvbible.txt
  Time (mean ± σ):      77.0 ms ±   1.1 ms    [User: 69.1 ms, System: 5.3 ms]
  Range (min … max):    75.7 ms …  81.5 ms    37 runs

@Bodigrim Bodigrim requested a review from Lysxia July 29, 2022 23:06
Copy link
Contributor

@Lysxia Lysxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Interesting trend that streaming is progressively losing ground.

@Bodigrim Bodigrim merged commit 8ae2888 into haskell:master Aug 2, 2022
@Bodigrim Bodigrim deleted the toLower branch August 2, 2022 22:40
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

Successfully merging this pull request may close these issues.

toLower is slow
4 participants