[racket-dev] member like assoc
Do the times change if you put an 'in-range' in the for loops?
On Sunday, June 9, 2013, Asumu Takikawa wrote:
> On 2013-05-31 19:40:52 -0400, Asumu Takikawa wrote:
> > Is it feasible to get `member` to have the same optional argument
> > behavior as `assoc`? That is, to have an equality predicate as the third
> > argument.
>
> I went ahead and implemented this behavior and submitted a pull request:
> https://github.com/plt/racket/pull/366
>
> To see if the change is "pay as you go", I ran some microbenchmarks to
> see if old-style `member` calls would slow down (see below). There
> doesn't seem to be any significant slow-down AFAICT.
>
> I was surprised that the non-JIT version was faster in the first case
> but much slower in the second microbenchmark though. (note: I had to
> change the C implementation of `member` for the non-JIT path)
>
> I'd appreciate any suggestions on the code.
>
> Cheers,
> Asumu
>
> ;;; NEW BRANCH
> $ racket member-benchmark.rkt
> cpu time: 1748 real time: 1752 gc time: 0
> $ racket --no-jit member-benchmark.rkt
> cpu time: 1524 real time: 1526 gc time: 0
>
> ;;; MASTER
> $ racket member-benchmark.rkt
> cpu time: 1712 real time: 1716 gc time: 0
> $ racket --no-jit member-benchmark.rkt
> cpu time: 1524 real time: 1528 gc time: 0
>
> The microbenchmark is just this:
> #lang racket/base
> (require (only-in racket/list range))
> (define lst (range 1 5000))
> (time
> (for ([i 30000])
> (member 2500 lst)))
>
> On a slightly different microbenchmark:
>
> ;;; NEW BRANCH
> $ racket member-benchmark-2.rkt
> cpu time: 2396 real time: 2402 gc time: 0
> $ racket --no-jit member-benchmark-2.rkt
> cpu time: 7156 real time: 7174 gc time: 0
>
> ;;; MASTER
> $ racket member-benchmark-2.rkt
> cpu time: 2412 real time: 2416 gc time: 0
> $ racket --no-jit member-benchmark-2.rkt
> cpu time: 6892 real time: 6911 gc time: 0
>
> #lang racket/base
> (define lst '(a b c))
> (time
> (for ([i 30000000])
> (member 'b lst)))
>
> _________________________
> Racket Developers list:
> http://lists.racket-lang.org/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130609/b1bfbd34/attachment.html>