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

Cache time representation. #149

Merged
merged 11 commits into from
Aug 22, 2024
Merged

Cache time representation. #149

merged 11 commits into from
Aug 22, 2024

Conversation

cheatfate
Copy link
Contributor

@cheatfate cheatfate commented Apr 30, 2024

According to my benchmarks this gives 18% performance boost on Linux.
Latest version gives over 100% performance boost on Linux.

@cheatfate
Copy link
Contributor Author

cheatfate commented Jun 20, 2024

I have improved algorithm and using this example i have benchmarked original and improved version in Linux VM using redirection to file (to avoid terminal performance problems).

import chronicles, std/monotimes

const TestsCount = 6000000

proc testFoo() =
  let start = getMonoTime()
  for i in 0 ..< TestsCount:
    info "Performance check", index = i
  echo "It takes ", getMonoTime() - start

when isMainModule:
  testFoo()

Original version

It takes (seconds: 47, nanosecond: 561114303) = 47.561 = 126153 lines/sec
It takes (seconds: 47, nanosecond: 945328972) = 47.945 = 125143 lines/sec
It takes (seconds: 47, nanosecond: 265613714) = 47.265 = 126943 lines/sec
It takes (seconds: 49, nanosecond: 303206524) = 49.303 = 121696 lines/sec
It takes (seconds: 48, nanosecond: 444603490) = 48.444 = 123854 lines/sec

Average performance = 124757 lines/sec

Improved version

It takes (seconds: 21, nanosecond: 419377659) = 21.419 = 280125 lines/sec
It takes (seconds: 20, nanosecond: 913452058) = 20.913 = 286902 lines/sec
It takes (seconds: 19, nanosecond: 751597292) = 19.751 = 303782 lines/sec
It takes (seconds: 18, nanosecond: 108224670) = 18.108 = 331345 lines/sec
It takes (seconds: 22, nanosecond: 91658474) = 22.916 = 261825 lines/sec

Average performance = 292795 lines/sec

Performance boost 134.69%

Comment on lines 440 to 441
let tmp = $sec
res[1] = tmp[0]
Copy link
Member

@arnetheduck arnetheduck Aug 9, 2024

Choose a reason for hiding this comment

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

Suggested change
let tmp = $sec
res[1] = tmp[0]
res[1] = '0' + char(sec)

etc .. can avoid the memory allocations here

@cheatfate cheatfate merged commit a28bb97 into master Aug 22, 2024
12 checks passed
@cheatfate cheatfate deleted the cache-time branch August 22, 2024 11:04
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.

2 participants