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