@Raul: Frankly, I didn't try to understand neither the specs for the checksum, nor what was going on in the Python code. I just copied it, adapted it, and made sure my version yields the same as python.
@Henry: it seemed like that in my previous test, indeed. however, I tried on a different computer where I do have different versions of J available, but found the difference very small. The test with Python was a lot faster here as well. I guess the difference I reported yesterday was more due to a speedup in the Python interpreter (between 3.8.x on my pc vs. 3.9.y on my phone) than between J versions. Another explanation could be that there's a huge (relative) difference between non-avx (my phone), avx (my pc used for my previous comparison) and avx2 (reported below). The results of my new comparison (j901, j902, j903-beta o, python 3.9.5) are: 100 runs in: j901: 1m11,783s j902: 1m12,730s j903: 1m11,945s pyhon: 0m18,722s So it seems mostly that the python interpreter made a speed jump between 3.8 (used for my first test) and 3.9 (used in the above test). More details below: ## j901## ~/j901/bin/jconsole -js 'exit 0: echo JVERSION' Engine: j901/j64avx/linux Release-f: commercial/2020-06-11T15:57:46 Library: 9.01.24 Platform: Linux 64 Installer: J901 install InstallPath: /home/jpjacobs/j901 Contact: www.jsoftware.com time for((i=0;i<100;++i)); do ~/j901/bin/jconsole fannkuch-redux901.ijs 8; done real 1m11,783s user 1m9,646s sys 0m1,236s ## j902 ## ~/j902/bin/jconsole -js 'exit 0: echo JVERSION' Engine: j902/j64avx/linux Release-b: commercial/2021-02-18T11:51:27 Library: 9.02.08 Platform: Linux 64 Installer: J902 install InstallPath: /home/jpjacobs/j902 Contact: www.jsoftware.com time for((i=0;i<100;++i)); do ~/j902/bin/jconsole fannkuch-redux_noai.ijs 8 ;done real 1m12,730s user 1m10,801s sys 0m1,018s ## j903 ## ~/j903/bin/jconsole -js 'exit 0: echo JVERSION' Engine: j903/j64avx/linux Beta-o: commercial/2021-08-24T18:59:22 Library: 9.03.06 Platform: Linux 64 Installer: J903 install InstallPath: /home/jpjacobs/j903 Contact: www.jsoftware.com time for((i=0;i<100;++i)); do ~/j903/bin/jconsole fannkuch-redux_noai.ijs 8 ;done real 1m11,945s user 1m9,551s sys 0m1,035s ## python 3.9.5 ## python --version Python 3.9.5 time for((i=0;i<100;++i)); do python fannkuch-redux.py 8; done real 0m18,722s user 0m17,733s sys 0m0,999s On Mon, Sep 6, 2021, 19:13 Raul Miller <[email protected]> wrote: > I did not see the ordering of the permutations specified in the > benchmark. And, the order should not matter (since both >. and + are > both commutative and associative, and those are what we are using to > combine the values obtained from the different permutations). > > However, changing the while. in my bgame1 to whilst. might be > necessary. (This will change the number of iterations when 1 is the > first value in the permutation.) > > That said, if the checksum is positive for length two permutations, > that implementation has not fully implemented the benchmark as > documented at > https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/fannkuchredux.html > > For length 2 permutations, there are two permutations to consider: 1 2 > and 2 1. These either both require 1 flip or one of them requires 1 > flip and the other requires 0 flips. And the benchmark states that odd > flip counts are negative. > > FYI, > > -- > Raul > > > > On Mon, Sep 6, 2021 at 12:55 PM Jan-Pieter Jacobs > <[email protected]> wrote: > > > > Hi Raul, > > > > The output produced by the python version is: > > Pfannkuchen(2) = 1 > > 2 > > Pfannkuchen(3) = 2 > > 4 > > Pfannkuchen(4) = 4 > > 11 > > Pfannkuchen(5) = 7 > > 49 > > Pfannkuchen(6) = 10 > > 228 > > Pfannkuchen(7) = 16 > > > > with the bare numbers being the checksums, so it seems there's something > > off with the checksums. > > > > Note that the permutations are not in the order A. produces them for > (i.e. > > (i.!n)A. i. n). You can get the order used by using a negative number as > > input to either the J or python script I provided. > > > > Jan-Pieter > > > > On Mon, Sep 6, 2021, 17:00 Raul Miller <[email protected]> wrote: > > > > > I am not quite sure that I have implemented this properly (I didn't > > > see any example results to check against), but I think that this > > > should be close to what that benchmark asks for: > > > > > > bgame1=:{{ > > > P=. y > > > N=. 0 > > > while. 1~:{.P do. > > > N=. N+1 > > > F=. {.P > > > P=. (|.F{.P) (i.F)} P > > > end. > > > N > > > }} > > > > > > bgame=:{{ > > > P=. i.y > > > CHK=.MAX=. 0 > > > for_J. i.!y do. > > > MAX=.MAX>.N=. bgame1 1+J A. P > > > CHK=. CHK+N*_1^2|N > > > end. > > > MAX,CHK > > > }} > > > > > > bgame 7 > > > 16 _108 > > > timespacex 'bgame 7' > > > 0.016073 69408 > > > > > > If my result here seems to be correct, implementing a "parallel" > > > version which spins up multiple J instances should be relatively > > > straightforward. > > > > > > I hope this helps, > > > > > > -- > > > Raul > > > > > > On Mon, Sep 6, 2021 at 9:49 AM Jan-Pieter Jacobs > > > <[email protected]> wrote: > > > > > > > > Hi, > > > > > > > > I converted one of the BenchmarkGame problem's python solution ( > > > > > > > > https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/fannkuchredux.html > > > ) > > > > to J. > > > > I just transliterated the Python solution (including all the stinking > > > > loops, ugly workarounds for generators etc), sticking to the > original as > > > > much as possible, so I am sure a faster solution must exist in J, > and I > > > > also did not implement the parallel part of the python solution once > > > > arguments get large: this solution works till permutations of length > 8. > > > > This is mainly because I wrote this on my phone and neither J's nor > > > > Python's parallelism is supported on my OS. > > > > > > > > The scripts used are in attachment (strip the .txt from the names) > > > > > > > > Results (abbreviated output; ran in powershell on Windows 10 on an > Intel > > > > core i7-8665U): > > > > > > > > PS C:\Users\myuser\j903-user\temp> Measure-Command { For($i=0; $i -lt > > > 100; > > > > $i++) {..\..\j903\bin\jconsole.exe fannkuch-redux_noai.ijs 8}} > > > > > > > > TotalMilliseconds : 53978,1287 > > > > > > > > PS C:\Users\myuser\j903-user\temp> Measure-Command { For($i=0; $i -lt > > > 100; > > > > $i++) {python fannkuch-redux.py 8}} > > > > > > > > TotalMilliseconds : 50086,8826 > > > > > > > > PS C:\Users\myuser\j903-user\temp> python --version > > > > Python 3.8.3 > > > > > > > > PS C:\Users\myuser\j903-user\temp> ..\..\j903\bin\jconsole.exe -js > 'exit > > > 0: > > > > echo JVERSION' > > > > Engine: j903/j64avx2/windows > > > > Beta-o: commercial/2021-08-24T18:57:03 > > > > Library: 9.03.06 > > > > Platform: Win 64 > > > > Installer: J903 install > > > > InstallPath: c:/users/myuser/j903 > > > > Contact: www.jsoftware.com > > > > > > > > 100 * 53978.1287 % 50086.8826 > > > > 107.769 > > > > > > > > Jconsole takes 7.8% longer than Python averaged over 100 runs. > > > > > > > > Which is quite good, I think, when compared with j903-beta a (most > recent > > > > available for my phone, Android 32 (armeabi-v7a)) and python 3.9.6; > there > > > > 50 runs of J took 2m19.879s vs. python 0m49.456s. > > > > > > > > That is, J takes 182.8% longer than Python, averaged over 50 runs! > > > > > > > > I'm also curious to see how the best J solution ranks compared to the > > > > above, as well as the paralnel version. > > > > > > > > > > > > Best regards, > > > > > > > > Jan-Pieter > > > > > > > > On Sun, Aug 29, 2021, 04:59 Henry Rich <[email protected]> wrote: > > > > > > > > > In beta-o I have rewritten the parser one more time. I don't see > how > > > it > > > > > can get much faster. In a weakly-typed language like J there is > only > > > so > > > > > much analysis that can be done before executing a sentence. I > wonder > > > > > how J performs compared to other popular languages, especially > Python > > > > > which is what the cool kids are using. If anyone is willing to do > the > > > > > comparison, I'd be obliged. > > > > > > > > > > I am thinking of measuring the execution time of a simple program, > one > > > > > that does scalar-only operations so we are focusing on the > parser. A > > > > > sample J program would be: > > > > > > > > > > v =: {{ totl =. 0 for_i. y do. totl =. totl + i * i_index end. > totl }} > > > > > 10 (6!:2) 'v a' [ a =. i. 1e6 > > > > > > > > > > Large improvement would require heroic intervention: parsing & > caching > > > > > sentences on the fly & watching assignments to make sure the > cached > > > > > parse is valid. I would rather avoid that. > > > > > > > > > > Henry Rich > > > > > > > > > > -- > > > > > This email has been checked for viruses by AVG. > > > > > https://www.avg.com > > > > > > > > > > > ---------------------------------------------------------------------- > > > > > For information about J forums see > http://www.jsoftware.com/forums.htm > > > > > > > > > > ---------------------------------------------------------------------- > > > > For information about J forums see > http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
