thanks very much for both those solutions.
The first (with $:) is very slow with large inputs. The 2nd pretty good. The
tacit vs. explicit favours tacit for short circuiting about 5k items or less.
With 2x performance advantage at 1k or less.
For larger test the explicit version stays at linear performance and so beats
the tacit version with larger inputs.
A lesson from your examples is that $: should only be used when the length of y
is significantly reduced on each call (generally not a simple }.). $: also
uses significant memory.
ts '+: repeatuntil (6 < ]) ( 1e4 $ 2) , 2 1 3 2 4 5 2'
50.9872/sec 0.270464MB
ts '{.@(}.^:(6>:{.)^:_@: +:) ( 1e4 $ 2) , 2 1 3 2 4 5 2'
17.217/sec 1.97286MB
10 ts '{.@(}.^:(6>:{.)^:_@: +:) ( 1e2 $ 2) , 2 1 3 2 4 5 2'
10289.8/sec 0.022144MB
ts '+: repeatuntil (6 < ]) ( 1e2 $ 2) , 2 1 3 2 4 5 2'
4568.72/sec 0.010368MB
ts '+: repeatuntil (6 < ]) ( 1e3 $ 2) , 2 1 3 2 4 5 2'
429.377/sec 0.024704MB
10 ts '{.@(}.^:(6>:{.)^:_@: +:) ( 1e3 $ 2) , 2 1 3 2 4 5 2'
815.481/sec 0.129664MB
10 ts '$:@}.`{.@.(6<{.)+: ( 1e3 $ 2) , 2 1 3 2 4 5 2'
340.615/sec 6.1033MB
----- Original Message -----
From: Aai <[email protected]>
To: [email protected]
Cc:
Sent: Sunday, November 17, 2013 4:24:45 AM
Subject: Re: [Jprogramming] repeatuntil and repeat while tacit definitions
possible?
$:@}.`{.@.(6<{.) +: 2 1 3 2 4 5 2
8
much slower
{.@(}.^:(6>:{.)^:_@: +:) 2 1 3 2 4 5 2
8
But I prefer Raul's solution.
On 17-11-13 03:38, Pascal Jasmin wrote:
> I spent some time describing the application. You can also think of the
> application as search every web page on every ipv4 until the first
> interesting thing is found. Maybe I care about a 2nd interesting thing,
> maybe I don't. But I'd like to see the first before I ask for another, and
> the approach of finding them all and then returning the first is not
> practical.
>
> The explicit version I provided is not unworkable. I was hoping that there
> is a version with {. and $:@:}.
>
>
> ----- Original Message -----
> From: Raul Miller <[email protected]>
> To: Programming forum <[email protected]>
> Cc:
> Sent: Saturday, November 16, 2013 8:56:03 PM
> Subject: Re: [Jprogramming] repeatuntil and repeat while tacit definitions
> possible?
>
> ({~ 1 i.~ 6 < ]) +: 2 1 3 2 4 5 2
> 8
> ({.~ 1 i.~ 6 < ]) +: 2 1 3 2 4 5 2
> 4 2 6 4
>
> Now you might argue that this is not the same thing. But it is the same
> result.
>
> It's just faster to compute this way. And, ok, I understand that speed
> is not necessarily desirable. But I think in this case you might want
> to just use a different language.
>
--
Met vriendelijke groet,
@@i = Arie Groeneveld
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm