Closed thangngoc89 closed 6 years ago
I created a benchmark here https://rebench.github.io/?rebench-data=NoIgNgpgLgBAHjAvDALAJgNwHoBUMDOAFgIYBOEAJjAMYD2FEMA5rRPjIROTDliADTBQAZgEgAVvjEIA1DAA6IAA5xFIALqCQaMeTEBvcQB8AJAAo4AShVHxAXw1aAjLohj8UUgEsAdkwD6tABm-r5QFpYwMnKKKmrqCUA
Since I’m on mobile, the result maybe unreliable. Could any of you run it on a laptop and report it back here?
thanks! I'm only just learning reason, so this is good to know. I'm trying to keep this to pure reason, so any idea how this will compile to native?
I also checked with rollup + closure(simple), and string_of_int gets inlined, making it as fast as the 3rd one.
I also messed with the benchmark, and it appears the advantage disappears when you're actually doing something with the value (note that the 3rd output doesn't return anything). eg - adding a console.log(value) brings them all closer together.
If you use the bucklescript specific implementation I don't think it will compile to native. Maybe bucklescript should compile string_of_int
down to the second example if possible. cc @bobzhang
After posting this issue, it appears that this is string_of_int:
function string_of_int (x) {
return "" + x
}
So it's actually what I would write in JS. Sorry for the noises. So the only advantage of using {j I can think of is it's much easier to use
I'll close this out for now, but feel free to carry on
As I can see, nice is a string concatenation library and you used ocaml function like string_of_int a lot. But calling these function should have some performance cost.
Example:
Link here https://reasonml.github.io/try/?reason=DYUwLgBAZg9jEF4IAoAeBKRA+CBnMATgJYB2A5gPoxQWlhqYDUjEARAA6qsDcAUKJABGAQwKIUqAFwQ6mBDgDeAKwA+AEgYqlAX25A
Bucklescript docs on string interpolation https://bucklescript.github.io/docs/en/common-data-types.html#interpolation