Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-28 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 21:46:08 UTC, Bruce Carneal wrote: On Thursday, 27 February 2020 at 19:46:23 UTC, Basile B. wrote: [...] The code below is the test jig that I'm using currently. It is adopted from yours but has added the -d=distribution command line option. [...] Yes I

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-28 Thread 9il via Digitalmars-d-learn
On Friday, 28 February 2020 at 10:11:23 UTC, Bruce Carneal wrote: On Friday, 28 February 2020 at 06:50:55 UTC, 9il wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-28 Thread kinke via Digitalmars-d-learn
On Friday, 28 February 2020 at 10:11:23 UTC, Bruce Carneal wrote: On Friday, 28 February 2020 at 06:50:55 UTC, 9il wrote: bsr can be done in one/two CPU operation, quite quick. But core.bitop.bsr wouldn't be inlined. Instead, mir-core (mir.bitop: ctlz) or LDC intrinsics llvm_ctlz can be used

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-28 Thread Bruce Carneal via Digitalmars-d-learn
On Friday, 28 February 2020 at 10:11:23 UTC, Bruce Carneal wrote: On Friday, 28 February 2020 at 06:50:55 UTC, 9il wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-28 Thread Bruce Carneal via Digitalmars-d-learn
On Friday, 28 February 2020 at 06:50:55 UTC, 9il wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. [...] bsr can

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread 9il via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. [...] bsr can be done in one/two CPU operation, quite quick. But

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Bruce Carneal via Digitalmars-d-learn
On Thursday, 27 February 2020 at 19:46:23 UTC, Basile B. wrote: Yes please, post the benchmark method. You see the benchmarks I run with your version are always slowest. I'm aware that rndGen (and generaly any uniform rnd func) is subject to a bias but I dont thing this bias maters much in the

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 17:17:32 UTC, Bruce Carneal wrote: On Thursday, 27 February 2020 at 17:11:48 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 15:29:02 UTC, Bruce Carneal wrote: On Thursday, 27 February 2020 at 08:52:09 UTC, Basile B. wrote: I will post my code if there

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Bruce Carneal via Digitalmars-d-learn
On Thursday, 27 February 2020 at 17:11:48 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 15:29:02 UTC, Bruce Carneal wrote: On Thursday, 27 February 2020 at 08:52:09 UTC, Basile B. wrote: I will post my code if there is any meaningful difference in your subsequent results. give me

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 15:29:02 UTC, Bruce Carneal wrote: On Thursday, 27 February 2020 at 08:52:09 UTC, Basile B. wrote: I will post my code if there is any meaningful difference in your subsequent results. give me something I can compile and verify. I'm not there to steal, if you

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Bruce Carneal via Digitalmars-d-learn
On Thursday, 27 February 2020 at 15:29:02 UTC, Bruce Carneal wrote: big snip TL;DR for the snipped: Unsurprisingly, different inputs will lead to different timing results. The equi-probable values supplied by a standard PRNG differ significantly from an equi-probable digit input. In

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 14:12:35 UTC, Basile B. wrote: On Wednesday, 26 February 2020 at 22:07:30 UTC, Johan wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: [...] Hi Basile, I recently saw this presentation: https://www.youtube.com/watch?v=Czr5dBfs72U

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Bruce Carneal via Digitalmars-d-learn
On Thursday, 27 February 2020 at 08:52:09 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 04:44:56 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 03:58:15 UTC, Bruce Carneal wrote: Maybe you talked about another implementation of decimalLength9 ? Yes. It's one I wrote after

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 22:07:30 UTC, Johan wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: [...] Hi Basile, I recently saw this presentation: https://www.youtube.com/watch?v=Czr5dBfs72U Andrei made a talk about this too a few years ago. It has some

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 09:41:20 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 09:33:28 UTC, Dennis Cote wrote: [...] Sorry but no. I think that you have missed how this has changed since the first message. 1. the way it was tested initially was wrong because LLVM was

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 09:33:28 UTC, Dennis Cote wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. Perhaps

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Dennis Cote via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. Perhaps you could try something like this. int decimalDigitLength(ulong

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 04:44:56 UTC, Basile B. wrote: On Thursday, 27 February 2020 at 03:58:15 UTC, Bruce Carneal wrote: Maybe you talked about another implementation of decimalLength9 ? Yes. It's one I wrote after I saw your post. Psuedo-code here: auto d9_branchless(uint v)

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 February 2020 at 03:58:15 UTC, Bruce Carneal wrote: Maybe you talked about another implementation of decimalLength9 ? Yes. It's one I wrote after I saw your post. Psuedo-code here: auto d9_branchless(uint v) { return 1 + (v >= 10) + (v >= 100) ... } Using ldc to target

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Bruce Carneal via Digitalmars-d-learn
On Thursday, 27 February 2020 at 03:58:15 UTC, Bruce Carneal wrote: On Wednesday, 26 February 2020 at 23:09:34 UTC, Basile B. wrote: On Wednesday, 26 February 2020 at 20:44:31 UTC, Bruce Carneal wrote: After shuffling the input, branchless wins by 2.4X (240%). snip Let me know if the

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Bruce Carneal via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 23:09:34 UTC, Basile B. wrote: On Wednesday, 26 February 2020 at 20:44:31 UTC, Bruce Carneal wrote: After shuffling the input, branchless wins by 2.4X (240%). I've replaced the input by the front of a rndGen (that pops for count times and starting with a

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 20:44:31 UTC, Bruce Carneal wrote: The winning function implementation lines up with that distribution. It would not fare as well with higher entropy input. Using sorted equi-probable inputs (N 1 digit numbers, N 2 digit numbers, ...) decimalLength9_0 beats

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 22:07:30 UTC, Johan wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: [...] Hi Basile, I recently saw this presentation: https://www.youtube.com/watch?v=Czr5dBfs72U It has some ideas that may help you make sure your measurements are

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Johan via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. ... Then bad surprise. Even with ldmd (so ldc2 basically) feeded with

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Bruce Carneal via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 19:44:05 UTC, Bruce Carneal wrote: On Wednesday, 26 February 2020 at 13:50:11 UTC, Basile B. wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: ... foreach (i; 0 .. count) sum += funcs[func](i); The input stream is highly

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Bruce Carneal via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 13:50:11 UTC, Basile B. wrote: On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: ... foreach (i; 0 .. count) sum += funcs[func](i); The input stream is highly predictable and strongly skewed towards higher digits. The winning

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: How is that possible ? It turns out that there's a problem with the benchmarking method. With command line argument the different optimization passes of LLVM don't fuck up with the literal constants. It appears that none of

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-26 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 00:50:35 UTC, Basile B. wrote: So after reading the translation of RYU I was interested too see if the decimalLength() function can be written to be faster, as it cascades up to 8 CMP. [...] It can be made faster using binary search. Not by much though.

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-25 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 February 2020 at 01:10:07 UTC, H. S. Teoh wrote: On Wed, Feb 26, 2020 at 12:50:35AM +, Basile B. via Digitalmars-d-learn wrote: [...] #!dmd -boundscheck=off -O -release -inline [...] TBH, I'm skeptical of any performance results using dmd. I wouldn't pay attention to

Re: Strange counter-performance in an alternative `decimalLength9` function

2020-02-25 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 26, 2020 at 12:50:35AM +, Basile B. via Digitalmars-d-learn wrote: [...] > #!dmd -boundscheck=off -O -release -inline [...] TBH, I'm skeptical of any performance results using dmd. I wouldn't pay attention to performance numbers obtained this way, and rather look at the