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

[Experimental] Monotonic encode with less abstraction #220

Closed
wants to merge 5 commits into from

Conversation

kachick
Copy link
Owner

@kachick kachick commented Jul 20, 2022

Follow #213 in MonotonicGenerator

```
/home/kachick/.rubies/ruby-3.1.2/bin/ruby benchmark/generate_vs_encode.rb
Warming up --------------------------------------
         ULID.encode    15.911k i/100ms
  ULID.generate.to_s    14.175k i/100ms
       ULID.generate    14.284k i/100ms
ULID.parse(ULID.encode)
                         9.858k i/100ms
Calculating -------------------------------------
         ULID.encode    163.134k (± 2.7%) i/s -    827.372k in   5.076016s
  ULID.generate.to_s    142.584k (± 2.6%) i/s -    722.925k in   5.073685s
       ULID.generate    143.053k (± 2.2%) i/s -    728.484k in   5.094885s
ULID.parse(ULID.encode)
                         96.058k (± 1.8%) i/s -    483.042k in   5.030270s

Comparison:
         ULID.encode:   163134.4 i/s
       ULID.generate:   143053.1 i/s - 1.14x  (± 0.00) slower
  ULID.generate.to_s:   142584.2 i/s - 1.14x  (± 0.00) slower
ULID.parse(ULID.encode):    96058.3 i/s - 1.70x  (± 0.00) slower
```
@kachick kachick added enhancement New feature or request performance Optimized for performance monotonicity labels Jul 20, 2022
```
ruby benchmark/monotonic_generators_with_now.rb
Warming up --------------------------------------
         ULID.encode    16.422k i/100ms
ULID::MonotonicGenerator#encode
                        13.716k i/100ms
ULID::MonotonicGenerator#generate.to_s
                        12.509k i/100ms
Calculating -------------------------------------
         ULID.encode    159.103k (± 6.3%) i/s -    804.678k in   5.080926s
ULID::MonotonicGenerator#encode
                        138.566k (± 0.8%) i/s -    699.516k in   5.048617s
ULID::MonotonicGenerator#generate.to_s
                        125.773k (± 0.7%) i/s -    637.959k in   5.072585s

Comparison:
         ULID.encode:   159102.5 i/s
ULID::MonotonicGenerator#encode:   138565.6 i/s - 1.15x  (± 0.00) slower
ULID::MonotonicGenerator#generate.to_s:   125772.8 i/s - 1.26x  (± 0.00) slower

ruby benchmark/monotonic_generators_with_different_time.rb
Warming up --------------------------------------
ULID.encode with different time
                        20.901k i/100ms
ULID::MonotonicGenerator#encode with different time
                        17.098k i/100ms
ULID::MonotonicGenerator#generate.to_s with different time
                        15.025k i/100ms
Calculating -------------------------------------
ULID.encode with different time
                        206.509k (± 1.5%) i/s -      1.045M in   5.061774s
ULID::MonotonicGenerator#encode with different time
                        170.083k (± 0.9%) i/s -    854.900k in   5.026802s
ULID::MonotonicGenerator#generate.to_s with different time
                        147.626k (± 1.5%) i/s -    751.250k in   5.090018s

Comparison:
ULID.encode with different time:   206509.5 i/s
ULID::MonotonicGenerator#encode with different time:   170083.3 i/s - 1.21x  (± 0.00) slower
ULID::MonotonicGenerator#generate.to_s with different time:   147626.3 i/s - 1.40x  (± 0.00) slower
```
kachick added a commit that referenced this pull request Jul 20, 2022
kachick added a commit that referenced this pull request Jul 20, 2022
@kachick kachick changed the title [Experimental] Monotonic encode [Experimental] Monotonic encode with less abstraction Jul 20, 2022
@kachick kachick closed this in #222 Jul 20, 2022
kachick added a commit that referenced this pull request Jul 20, 2022
Closes #220

I have tried to avoid object creation in `ULID::MonotonicGenerator` as #220. However it made **SLOWER** than now 🐌
And the current speed is acceptable. So I would just backport some refactoring code. 👋
@kachick kachick deleted the monotonic-encode branch July 21, 2022 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request monotonicity performance Optimized for performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant