Re: [racket-users] Re: Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread Shu-Hung You
Interesting. This is the timing on Mac. Comparing to Alex's result,
the numbers roughly match "< 7s" v.s. "> 13s" while fact-1 is close.

$ racket
Welcome to Racket v7.2.0.3.
> (enter! "factorial.rkt")
"factorial.rkt"> (equal? (fact 10) (fact-1 10))
#t
"factorial.rkt"> (time (void (fact-1 10)))
cpu time: 313 real time: 314 gc time: 2
"factorial.rkt"> (time (void (fact 10)))
cpu time: 6185 real time: 6265 gc time: 974

The GC time of fact differs a lot.

On Sun, Mar 24, 2019 at 9:26 PM Alex Harsanyi  wrote:
>
> You can check if the big number multiplication is the problem, by using a 
> factorial version which does not need so many big number multiplications:
>
> #lang racket/base
> (require racket/math)
> (define (fact n)
>   (if (zero? n) 1 (* n (fact (- n 1)
>
> (define (fact-1 n)
>   (define nslots (exact-truncate (sqrt n)))
>   (if (<= nslots 1)
>   (fact n) ;; use simple implementation for small numbers
>   (let ((slot (make-vector nslots 1)))
> (for ([x (in-range 1 (add1 n))])
>   (define index (modulo x nslots))
>   (vector-set! slot index (* (vector-ref slot index) x)))
> (for/fold ([result 1])
>   ([n (in-vector slot)])
>   (* result n)
>
> On my Windows machine, the difference between the two is huge: 16.7 seconds 
> for `fact` (your original implementation)  and only 0.5 seconds for `fact-1`
>
> > (equal? (fact 10) (fact-1 10))
> #t
> > (time (void (fact-1 10)))
> cpu time: 469 real time: 468 gc time: 111
> > (time (void (fact 10)))
> cpu time: 16797 real time: 16782 gc time: 7082
> >
>
>
>
> On Monday, March 25, 2019 at 1:20:33 AM UTC+8, Phil Nguyen wrote:
>>
>> With Racket 7.2, the following program takes >13 seconds to run on Windows, 
>> and <7 seconds on Linux either on Virtualbox on the same machine, or native 
>> Linux on another machine with slightly lower-powered processor:
>>
>> #lang racket/base
>> (define (fact n)
>>   (if (zero? n) 1 (* n (fact (- n 1)
>> (time (void (fact 10)))
>>
>> ; Windows native, i7-7660U
>> ;   cpu time: 13610 real time: 13633 gc time: 4459
>> ; Linux on Virtualbox, i7-7660U
>> ;   cpu time: 6691 real time: 6706 gc time: 1298
>> ; Linux native, i7-8500Y:
>> ;   cpu time: 6894 real time: 6882 gc time: 1129
>>
>>
>>
>> While the difference is unlikely to matter in practice, given `fact 10` 
>> is a very large number, I'm curious what accounts for this difference? Is it 
>> some big-integer library that Racket relies on?
>
> --
> 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.


[racket-users] Re: Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread Alex Harsanyi
You can check if the big number multiplication is the problem, by using a 
factorial version which does not need so many big number multiplications:

#lang racket/base
(require racket/math)
(define (fact n)
  (if (zero? n) 1 (* n (fact (- n 1)

(define (fact-1 n)
  (define nslots (exact-truncate (sqrt n)))
  (if (<= nslots 1)
  (fact n) ;; use simple implementation for small numbers
  (let ((slot (make-vector nslots 1)))
(for ([x (in-range 1 (add1 n))])
  (define index (modulo x nslots))
  (vector-set! slot index (* (vector-ref slot index) x)))
(for/fold ([result 1])
  ([n (in-vector slot)])
  (* result n)

On my Windows machine, the difference between the two is huge: 16.7 seconds 
for `fact` (your original implementation)  and only 0.5 seconds for `fact-1`

> (equal? (fact 10) (fact-1 10))
#t
> (time (void (fact-1 10)))
cpu time: 469 real time: 468 gc time: 111
> (time (void (fact 10)))
cpu time: 16797 real time: 16782 gc time: 7082
> 



On Monday, March 25, 2019 at 1:20:33 AM UTC+8, Phil Nguyen wrote:
>
> With Racket 7.2, the following program takes >13 seconds to run on 
> Windows, and <7 seconds on Linux either on Virtualbox on the same machine, 
> or native Linux on another machine with slightly lower-powered processor:
>
> #lang racket/base
> (define (fact n)
>   (if (zero? n) 1 (* n (fact (- n 1)
> (time (void (fact 10)))
>
> ; Windows native, i7-7660U
> ;   cpu time: 13610 real time: 13633 gc time: 4459
> ; Linux on Virtualbox, i7-7660U
> ;   cpu time: 6691 real time: 6706 gc time: 1298
> ; Linux native, i7-8500Y:
> ;   cpu time: 6894 real time: 6882 gc time: 1129
>
>
>
> While the difference is unlikely to matter in practice, given `fact 10` 
> is a very large number, I'm curious what accounts for this difference? Is it 
> some big-integer library that Racket relies on?
>
>

-- 
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.


Re: [racket-users] Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread George Neuner


On 3/24/2019 1:20 PM, Phil Nguyen wrote:
With Racket 7.2, the following program takes >13 seconds to run on 
Windows, and <7 seconds on Linux either on Virtualbox on the same 
machine, or native Linux on another machine with slightly 
lower-powered processor:


|
#lang racket/base(define (fact n)(if(zero?n)1(*n (fact (-n 1)(time 
(void(fact 10)))
;Windowsnative,i7-7660U;  cpu time:13610real time:13633gc 
time:4459;Linuxon Virtualbox,i7-7660U;  cpu time:6691real time:6706gc 
time:1298;Linuxnative,i7-8500Y:;  cpu time:6894real time:6882gc time:1129

|

While the difference is unlikely to matter in practice, given `fact 10` is 
a very large number, I'm curious what accounts for this difference? Is it some 
big-integer library that Racket relies on?


I haven't paid attention to it recently, but in early 6.x versions I 
observed very large differences in bytecode compilation speeds ... on 
the order of 5 to 10 times with Linux (even on VM) the clear winner.  
See the discussion here:

https://groups.google.com/forum/#!searchin/racket-users/neuner$20linux%7Csort:date/racket-users/iisjAKujpFQ/GJxa-PhHXRoJ

Execution times for a linked executable or an application consisting of 
pre-compiled .zo files appeared to be roughly equivalent. Similarly, 
starting a linked executable appeared roughly equivalent, but Windows 
was 2..3 times slower than Linux at starting "racket "  [most 
likely due to checking the .zo files].


Note however that I was not benchmarking but rather working on a rather 
complicated web service, so I was judging execution speeds mainly from 
timestamping in my application logs.


George

--
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.


[racket-users] Intriguing performance difference between Windows and Linux on `(factorial 100000)`

2019-03-24 Thread Phil Nguyen
With Racket 7.2, the following program takes >13 seconds to run on Windows, 
and <7 seconds on Linux either on Virtualbox on the same machine, or native 
Linux on another machine with slightly lower-powered processor:

#lang racket/base
(define (fact n)
  (if (zero? n) 1 (* n (fact (- n 1)
(time (void (fact 10)))

; Windows native, i7-7660U
;   cpu time: 13610 real time: 13633 gc time: 4459
; Linux on Virtualbox, i7-7660U
;   cpu time: 6691 real time: 6706 gc time: 1298
; Linux native, i7-8500Y:
;   cpu time: 6894 real time: 6882 gc time: 1129



While the difference is unlikely to matter in practice, given `fact 10` is 
a very large number, I'm curious what accounts for this difference? Is it some 
big-integer library that Racket relies on?

-- 
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.


Re: [racket-users] SQL DB tooling

2019-03-24 Thread Jesse Alama



On 23 Mar 2019, at 5:40, Aidan Gauland wrote:

> I see that Racket has a couple of nice libraries for talking to SQL
> databases  and
> , but I have been unable to find any
> equivalent to the so-called "migrations" capability of DB libraries from
> other languages (see
>  and
>   for examples).  Is there
> anything like this for Racket, or even some language-agnostic, CLI tool
> that does the same thing?

Check out Bogdan Popa's north: https://pkgs.racket-lang.org/package/north .

-- 
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.