The '++' operator does not verify that the second argument is a list.
Therefore, the compiler will rewrite the first expression to simply:
[$F,$o,$o|Bar]
> However, I ran some benchmarks and it seems the optimization does not happen
> (on R15B).
> With a local dummy implementation of assert_list(Bar), I got that the first
> format is 50% slower than the second one.
Have you made sure that you run each test in a newly spawned process?
Do you run the test for long enough time?
If you have set up your benchmark environment properly, and your second
example is still faster, I can only assume that the code sits better in cache.
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
The '++' operator does not verify that the second argument is a list.Therefore, the compiler will rewrite the first expression to simply:
[$F,$o,$o|Bar]
Have you made sure that you run each test in a newly spawned process?
Do you run the test for long enough time?
Thanks Björn!
The '++' operator does not verify that the second argument is a list.Therefore, the compiler will rewrite the first expression to simply:
[$F,$o,$o|Bar]
Yes, thanks. For some weird reason I thought Erlang restricted the right side to be a list in such cases.Have you made sure that you run each test in a newly spawned process?Do you run the test for long enough time?
Running in a newly spawned process did the trick, the results are now consistent.I was already running it 1000 times, here is the code (without using spawn):
I assume having a "clean" heap (reducing the chance of garbage collection) is the reason why it is a good idea to run benchmarks in a newly spawned process?If you want to vary one parameter in a test, make sure all other parameters stays the same otherwise you have no idea what you are measuring!
Code loading, heaps, position of mars .. Everything has to be taken into account.
On 2012-06-01 12:07, Björn-Egil Dahlberg wrote:
The '++' operator does not verify that the second argument is a list.Therefore, the compiler will rewrite the first expression to simply:
[$F,$o,$o|Bar]
Yes, thanks. For some weird reason I thought Erlang restricted the right side to be a list in such cases.Have you made sure that you run each test in a newly spawned process?Do you run the test for long enough time?
Running in a newly spawned process did the trick, the results are now consistent.I was already running it 1000 times, here is the code (without using spawn):
I assume having a "clean" heap (reducing the chance of garbage collection) is the reason why it is a good idea to run benchmarks in a newly spawned process?If you want to vary one parameter in a test, make sure all other parameters stays the same otherwise you have no idea what you are measuring!
Code loading, heaps, position of mars .. Everything has to be taken into account.
The effect of Mars magnetic field on that of Earth, even if Earth's aphelion and the perihelion of Mars were to coincide and the interplanetary distance were to be at its theoretical minimum, is negligible compared to the normal variations in Earth's magnetic field.
Therefore it's very unlikely that the relative position of Mars would affect the probability of a memory bitflip occurring due to cosmic radiation and thus affecting the benchmark.