If you're willing to use vectors, then maybe you're also willing to
use a custom data structure? You could get much better performance
that way. Here's a half-baked example of what I mean. `map-once/h`,
below, returns a (normal list) of hole-lists. ("hole-list" is not a
good name. The offset doesn't really designate a hole in the list, but
the offset where the function should be applied.)
===

#lang racket/base

(require racket/match)

(struct hole-list (xs hole-offset fn))

(define (hole-list-empty? hxs)
  (match hxs
    [(hole-list (? pair?) _ _) #f]
    [_ #t]))

(define (hole-list-nonempty? hxs)
  (not (hole-list-empty? hxs)))

(define (hcar hxs)
  (match hxs
    [(hole-list (cons x _) 0 fn) (fn x)]
    [(hole-list (cons x _) _ _) x]))

(define (hcdr hxs)
  (match hxs
    [(hole-list (cons _ xs) n fn) (hole-list xs (sub1 n) fn)]))

(define-match-expander hcons
  (syntax-rules ()
    [(_ x xs) (and (? hole-list?)
                   (? hole-list-nonempty?)
                   (app hcar x)
                   (app hcdr xs))]))

(define-match-expander hnull
  (syntax-rules ()
    [(_) (and (? hole-list?)
              (? hole-list-empty?))]))

(define (hole-list->list hxs)
  (match hxs
    [(hnull) '()]
    [(hcons x xs) (cons x (hole-list->list xs))]))

(define (map-once/h fn xs)
  (for/list ([i (in-range (length xs))])
    (hole-list xs i fn)))


On Fri, Jun 19, 2015 at 4:33 PM, Luke Miles <rashreportl...@gmail.com> wrote:
> I timed all these with `sqr` on a list of 10000 `(random)`.
>
> Luke's (my) first one:
> cpu time: 4706 real time: 4699 gc time: 3673
>
> Luke's second one:
> cpu time: 5401 real time: 5393 gc time: 4136
>
> Jon's first one:
> cpu time: 9734 real time: 9728 gc time: 8007
>
> Jon's second one (tested on a vector of course):
> cpu time: 1198 real time: 1195 gc time: 883
>
> Jens' first one:
> cpu time: 5622 real time: 5618 gc time: 4800
>
> Jens' second one:
> cpu time: 4393 real time: 4391 gc time: 3935
>
>
> I thought Jens' second one would be faster. The vector's results are 
> promising.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to