diff --git a/remix/exp/struct.rkt b/remix/exp/struct.rkt new file mode 100644 index 0000000..ab6b1d9 --- /dev/null +++ b/remix/exp/struct.rkt @@ -0,0 +1,72 @@ +#lang racket/base +(require racket/unsafe/ops + ffi/unsafe) + +(define (test-struct N) + (struct the (f i r)) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (the (exact->inexact i) i (number->string i))) + (set! x (the-f t)) + (set! y (the-i t)) + (set! z (the-r t)))) + +(define (test-unsafe-struct N) + (struct the (f i r)) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (the (exact->inexact i) i (number->string i))) + (set! x (unsafe-struct-ref t 0)) + (set! y (unsafe-struct-ref t 1)) + (set! z (unsafe-struct-ref t 2)))) + +(define (test-unsafe*-struct N) + (struct the (f i r)) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (the (exact->inexact i) i (number->string i))) + (set! x (unsafe-struct*-ref t 0)) + (set! y (unsafe-struct*-ref t 1)) + (set! z (unsafe-struct*-ref t 2)))) + +(define (test-vector N) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (vector (exact->inexact i) i (number->string i))) + (set! x (vector-ref t 0)) + (set! y (vector-ref t 1)) + (set! z (vector-ref t 2)))) + +(define (test-unsafe-vector N) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (vector (exact->inexact i) i (number->string i))) + (set! x (unsafe-vector-ref t 0)) + (set! y (unsafe-vector-ref t 1)) + (set! z (unsafe-vector-ref t 2)))) + +(define (test-cstruct N) + (define-cstruct _the ([f _float] [i _int] [r _racket])) + (define x #f) + (define y #f) + (define z #f) + (for ([i (in-range N)]) + (define t (make-the (exact->inexact i) i (number->string i))) + (set! x (the-f t)) + (set! y (the-i t)) + (set! z (the-r t)))) + +(module+ test + (for ([p (in-list (list test-struct test-vector test-unsafe-struct test-unsafe*-struct test-unsafe-vector test-cstruct))]) + (printf "testing ~v\n" p) + (time (p 1000000))))