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

Found how to improve performance of the access operators #7

Open
planetis-m opened this issue May 1, 2022 · 2 comments
Open

Found how to improve performance of the access operators #7

planetis-m opened this issue May 1, 2022 · 2 comments

Comments

@planetis-m
Copy link
Owner

planetis-m commented May 1, 2022

Currently there's a consisted 50% decrease in performance (0.22ms -> 0.44ms) for both short and long strings compared to std.string in the parseBinInt benchmark. Tested with gcc and clang. Using templates instead of procs for [], it drops down to ~26% (0.3ms).

@planetis-m planetis-m changed the title Found how to improve performace of the access operators Found how to improve performance of the access operators May 1, 2022
@planetis-m
Copy link
Owner Author

Same issue as: nim-lang/Nim#18339

@planetis-m
Copy link
Owner Author

planetis-m commented Sep 1, 2022

This change in myParseBin did not improve performance versus making [] a template

    template longData(s: String): untyped = s.p
    template shortData(s: String): untyped =
      cast[ptr UncheckedArray[char]](addr s.short.data[0])

    if s.isLong:
      while i < last:
        case s.longData[i]
        of '_': discard
        of '0'..'1':
          output = output shl 1 or T(ord(s.longData[i]) - ord('0'))
          foundDigit = true
        else: break
        inc(i)
    else:
      while i < last:
        case s.shortData[i]
        of '_': discard
        of '0'..'1':
          output = output shl 1 or T(ord(s.shortData[i]) - ord('0'))
          foundDigit = true
        else: break
        inc(i)

Results:

ParseBin std.string:
  Collected 10000 samples in 2.0677 s
  Average time: 0.2060 ms
  Stddev  time: 0.0116 ms
  Min     time: 0.2025 ms
  Max     time: 0.4008 ms

ParseBin String: # with above change
  Collected 10000 samples in 3.0586 s
  Average time: 0.3050 ms
  Stddev  time: 0.0013 ms
  Min     time: 0.3039 ms
  Max     time: 0.4171 ms

ParseBin String: # with template
  Collected 10000 samples in 2.8379 s
  Average time: 0.2830 ms
  Stddev  time: 0.0051 ms
  Min     time: 0.2816 ms
  Max     time: 0.4381 ms

ParseBin String: # Current
  Collected 10000 samples in 4.4027 s
  Average time: 0.4395 ms
  Stddev  time: 0.0091 ms
  Min     time: 0.4384 ms
  Max     time: 1.2552 ms

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

1 participant