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

Improve #4

Merged
merged 22 commits into from
Nov 17, 2021
Merged

Improve #4

merged 22 commits into from
Nov 17, 2021

Conversation

tmck-code
Copy link
Owner

@tmck-code tmck-code commented Nov 17, 2021

Changes

Individually timed all functions and a few different approaches for each to settle on the fastest ones.

  • improve the fortune text-wrapping and printing (still has much room for improvement)
  • make a bindata.go that is better suited to the use case
    • I need fast random choice.
    • using the regular bindata maps, I have to loop to the random index using range which takes a while
    • store the pokemon cowfile data as a raw byte array that can be printed directly, without conversion

TODO

Next (aka eventually) I'll make my own go-bindata that can generate the optimised bindata file, until then I can just manually hack it in vscode as it's pretty quick to do

Benchmarks

TL;DR this release is ~1.6x faster than the previous one. Using the hyperfine timer (great tool btw)

~/P/d/pokesay-go hyperfine 'cat fortune.txt | pokesay' 'cat fortune.txt | ./pokesay'

Benchmark 1: cat fortune.txt | pokesay
  Time (mean ± σ):       8.7 ms ±   1.6 ms    [User: 5.6 ms, System: 4.7 ms]
  Range (min … max):     7.1 ms …  15.6 ms    196 runs

Benchmark 2: cat fortune.txt | ./pokesay
  Time (mean ± σ):       5.2 ms ±   1.2 ms    [User: 3.2 ms, System: 3.7 ms]
  Range (min … max):     4.1 ms …  10.1 ms    237 runs

Summary
  'cat fortune.txt | ./pokesay' ran
    1.66 ± 0.49 times faster than 'cat fortune.txt | pokesay'

this avoids them being added to the go.mod file
Just store everything in a gigantic array as the original bytes, select
a random item and print it directly
- includes separated name & categories
- removed the debug timer
Avoids repulling them too often
This file has been handcrafted for max efficiency, I'll make some code
to generate this in future, and for now I'll remove all go-bindata calls
Try to make sure we're not converting cowfiles every build
@tmck-code tmck-code merged commit 9171b75 into master Nov 17, 2021
@tmck-code tmck-code deleted the improve branch November 17, 2021 11:51
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.

1 participant