Added stress test: libmpfr C struct accessor vs. Racket struct accessor
This commit is contained in:
parent
cc8bd4f294
commit
f607a3b061
|
@ -44,7 +44,18 @@
|
|||
string->bigfloat
|
||||
;; Main constructor
|
||||
bf
|
||||
bigfloat-deserialize-info)
|
||||
bigfloat-deserialize-info
|
||||
;; Low-level stuff
|
||||
mpfr-lib
|
||||
get-mpfr-fun
|
||||
_rnd_t
|
||||
_prec_t
|
||||
_sign_t
|
||||
_exp_t
|
||||
_mpfr_size_limb_t
|
||||
_mpfr
|
||||
_mpfr-pointer
|
||||
(struct-out mpfr))
|
||||
|
||||
;; Arithmetic, comparison, and other functions are provided by the macros that create them
|
||||
|
||||
|
|
44
collects/tests/racket/stress/mpfr-ffi-call-vs-racket.rkt
Normal file
44
collects/tests/racket/stress/mpfr-ffi-call-vs-racket.rkt
Normal file
|
@ -0,0 +1,44 @@
|
|||
#lang racket/base
|
||||
|
||||
(require ffi/unsafe
|
||||
tests/stress
|
||||
math/private/bigfloat/mpfr)
|
||||
|
||||
(define mpfr-get-exp (get-mpfr-fun 'mpfr_get_exp (_fun _mpfr-pointer -> _exp_t)))
|
||||
(define mpfr-get-prec (get-mpfr-fun 'mpfr_get_prec (_fun _mpfr-pointer -> _prec_t)))
|
||||
(define mpfr-get-signbit (get-mpfr-fun 'mpfr_signbit (_fun _mpfr-pointer -> _int)))
|
||||
|
||||
(define (mpfr-signbit x)
|
||||
(if ((mpfr-sign x) . < . 0) 1 0))
|
||||
|
||||
(define n 1000000)
|
||||
|
||||
(let ([x (bf 2)])
|
||||
(stress
|
||||
20
|
||||
["mpfr-get-prec (FFI accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-get-prec x))]
|
||||
["mpfr-prec (Racket accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-prec x))]))
|
||||
|
||||
(let ([x (bf 2)])
|
||||
(stress
|
||||
20
|
||||
["mpfr-get-exp (FFI accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-get-exp x))]
|
||||
["mpfr-exp (Racket accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-exp x))]))
|
||||
|
||||
(let ([x (bf 2)])
|
||||
(stress
|
||||
20
|
||||
["mpfr-get-signbit (FFI accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-get-signbit x))]
|
||||
["mpfr-signbit (Racket accessor)"
|
||||
(for ([_ (in-range n)])
|
||||
(mpfr-signbit x))]))
|
Loading…
Reference in New Issue
Block a user