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

Strings concatenation performance #3

Open
sudo-nice opened this issue Feb 28, 2019 · 4 comments
Open

Strings concatenation performance #3

sudo-nice opened this issue Feb 28, 2019 · 4 comments

Comments

@sudo-nice
Copy link

I'm afraid, concatenation of strings is a disputable question at the moment.
For example, here are my results:

require "benchmark"
puts Crystal::DESCRIPTION

FOO = "foo"
BAR = "bar"

def method_1
  FOO + BAR
end

def method_2
  "#{FOO}#{BAR}"
end

Benchmark.ips do |bm|
  bm.report "method_1" { method_1 }
  bm.report "method_2" { method_2 }
end

method_1  58.65M ( 17.05ns) (± 0.73%)   32 B/op        fastest
method_2  11.84M ( 84.47ns) (± 1.14%)  208 B/op   4.95× slower

The benchmark was built with options --release --no-debug, if it matters.
Also, there is an issue on the topic.


Crystal 0.27.2 [60760a546] (2019-02-05)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu

@konung
Copy link
Owner

konung commented Feb 28, 2019

That's something that @asterite mentioned in this commit comment : cbc2ff6#r32484649

I'll have a chance to go over some of the other commits and issues over the weekend and see how it changes. Also something I've noticed: some benchmarks have very different results on Ubuntu vs Mac.

Specifically, there is a benchmark with Enumerable#count ( I haven't added it yet to repo) that shows 2x difference between two OSs

@sudo-nice
Copy link
Author

some benchmarks have very different results on Ubuntu vs Mac

Oh, I see, that's a misfortune. The only thing that I may suggest here, is to persuade potential visitors to question everything and test the cases with their real OS.

But the cases you provide are really great to see the alternatives, thank you for that.

@konung
Copy link
Owner

konung commented Feb 28, 2019

Yep. No problem. I'll be adding more as I think of them.

1 option I'm pondering is to automate this a bit with Docker - so that there is more of a common env for benchmarks. But I will add a warning that OS & version of LLVM may affect the final results, pretty wildly. I mean in most cases - 95% - it should be pretty much the same, but I've have seen where it varies.

For this me this was more of en exercise to learn more about Crystal, when it comes to specific app performance - it may vary wildly based on many other things, so all benchmarks come with a bit of inherent caveat.

@konung
Copy link
Owner

konung commented Feb 28, 2019

I;ll leave this open until I update the Readme.

@konung konung reopened this Feb 28, 2019
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

2 participants