Re: [racket-users] Narrow radix of string->number.

2016-12-31 Thread Robby Findler
(PS: those are the calls only in the special case that a fixnum was
supplied and it was base 10 or base 16.)

On Sat, Dec 31, 2016 at 2:05 PM, Robby Findler
 wrote:
> As one data point, here's a histogram of the 20k or so calls to
> number->string that happen during the start up of DrRacket (first
> entry in each list is the argument passed to number->string and the
> second is the number of times that call happened):
>
> '((0 2399)
>   (1 8116)
>   (2 4278)
>   (3 2196)
>   (4 1346)
>   (5 901)
>   (6 364)
>   (7 230)
>   (8 106)
>   (9 96)
>   (10 42)
>   (11 5)
>   (12 3)
>   (72 1)
>   (100 34)
>   (241 1))
>
> Two others apps we care about are building the documentation and
> recompiling all of the .zos in the main distribution.
>
> (But we might also just decide that we don't care if number->string is
> fast, too.)
>
> Robby
>
>
> On Sat, Dec 31, 2016 at 1:57 PM, Robby Findler
>  wrote:
>> On Sat, Dec 31, 2016 at 12:57 PM, Matthew Butterick  wrote:
>>> Is it cheating to avoid divisions by using table lookups?
>>
>> Everything is fair in love, war, and benchmarking. :)
>>
>> But this introduces an additional cost that's a little bit more
>> troublesome to measure. Specifically, each namespace that instantiates
>> `racket/base` will now take a tiny bit more space and take a tiny bit
>> longer to initialize. I think this would boil down to a judgment call,
>> but a first step before making that judgment call would be to get some
>> benchmarks we think are representative (that actually call
>> number->string) and figure out what inputs they supply (and how often
>> they supply them). Based on that, then minimize the size of the table
>> and then I'd say that we're in a good position to make the judgment
>> call.
>>
>> Robby

-- 
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] Narrow radix of string->number.

2016-12-31 Thread Robby Findler
As one data point, here's a histogram of the 20k or so calls to
number->string that happen during the start up of DrRacket (first
entry in each list is the argument passed to number->string and the
second is the number of times that call happened):

'((0 2399)
  (1 8116)
  (2 4278)
  (3 2196)
  (4 1346)
  (5 901)
  (6 364)
  (7 230)
  (8 106)
  (9 96)
  (10 42)
  (11 5)
  (12 3)
  (72 1)
  (100 34)
  (241 1))

Two others apps we care about are building the documentation and
recompiling all of the .zos in the main distribution.

(But we might also just decide that we don't care if number->string is
fast, too.)

Robby


On Sat, Dec 31, 2016 at 1:57 PM, Robby Findler
 wrote:
> On Sat, Dec 31, 2016 at 12:57 PM, Matthew Butterick  wrote:
>> Is it cheating to avoid divisions by using table lookups?
>
> Everything is fair in love, war, and benchmarking. :)
>
> But this introduces an additional cost that's a little bit more
> troublesome to measure. Specifically, each namespace that instantiates
> `racket/base` will now take a tiny bit more space and take a tiny bit
> longer to initialize. I think this would boil down to a judgment call,
> but a first step before making that judgment call would be to get some
> benchmarks we think are representative (that actually call
> number->string) and figure out what inputs they supply (and how often
> they supply them). Based on that, then minimize the size of the table
> and then I'd say that we're in a good position to make the judgment
> call.
>
> Robby

-- 
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] Narrow radix of string->number.

2016-12-31 Thread Robby Findler
On Sat, Dec 31, 2016 at 12:57 PM, Matthew Butterick  wrote:
> Is it cheating to avoid divisions by using table lookups?

Everything is fair in love, war, and benchmarking. :)

But this introduces an additional cost that's a little bit more
troublesome to measure. Specifically, each namespace that instantiates
`racket/base` will now take a tiny bit more space and take a tiny bit
longer to initialize. I think this would boil down to a judgment call,
but a first step before making that judgment call would be to get some
benchmarks we think are representative (that actually call
number->string) and figure out what inputs they supply (and how often
they supply them). Based on that, then minimize the size of the table
and then I'd say that we're in a good position to make the judgment
call.

Robby

-- 
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] Narrow radix of string->number.

2016-12-31 Thread Matthew Butterick
> On Dec 31, 2016, at 10:57 AM, Matthew Butterick  wrote:
> 
>> I started with Ryan's code from `~r` and tried to emulate some special
>> cases I see the C code (and didn't worry about negative numbers) and
>> ended up with something 4-5x slower than the C code version. :(  Code
>> follows.
> 
> 
> Is it cheating to avoid divisions by using table lookups? 


Whoops, my `test-it` macro had a typo in it. Here are results for different 
number lengths. 

; convert 123
cpu time: 893 real time: 925 gc time: 21; number->string
cpu time: 3306 real time: 3376 gc time: 74  ; number->string* (Findler 
algorithm)
cpu time: 583 real time: 614 gc time: 26; number->string** (table 
lookup)

; convert 123456
cpu time: 1393 real time: 1433 gc time: 38  ; number->string
cpu time: 5474 real time: 5544 gc time: 86  ; number->string* (Findler 
algorithm)
cpu time: 1325 real time: 1423 gc time: 79  ; number->string** (table 
lookup)

; convert 123456789
cpu time: 1950 real time: 1980 gc time: 46  ; number->string
cpu time: 7835 real time: 7882 gc time: 97  ; number->string* (Findler 
algorithm)
cpu time: 2293 real time: 2532 gc time: 174 ; number->string** (table 
lookup)


;;
#lang racket

(define (number->string* N)
 (cond [(zero? N)
(string #\0)]
   [else
(let* ([short-size 10]
   [str (make-string short-size)])
  (let loop ([N N] [digits null] [i short-size])
(cond
  [(zero? N)
   (if (<= i 0)
   (if (null? digits)
   str
   (string-append (apply string digits) str))
   (substring str i short-size))]
  [else
   (define-values (q r) (quotient/remainder N 10))
   (define d (integer->char (+ r (char->integer #\0
   (cond
 [(<= i 0)
  (loop q (cons d digits) i)]
 [else
  (string-set! str (- i 1) d)
  (loop q '() (- i 1))])])))]))


(define-syntax-rule (digit-vector id ...)
  (for*/vector ([id (in-range 10)] ...)
   (append (string->list (number->string id)) ...)))

(define number->string**
 (let ([digits (digit-vector i)]
   [double-digits (digit-vector i j)]
   [triple-digits (digit-vector i j k)])
   (λ (N)
 (list->string
  (let loop ([N N])
(cond
  [(< N 10) (vector-ref digits N)]
  [(< N 100) (vector-ref double-digits N)]
  [(< N 1000) (vector-ref triple-digits N)]
  [else
   (append (loop (quotient N 1000))
   (vector-ref triple-digits (remainder N 1000)))]))

(define-syntax-rule (test-it id ...)
 (begin
   (module+ test
 (require rackunit)
 (check-equal? (id 1234567890987654321)
   (number->string 1234567890987654321))
 (for ([x (in-range 1)])
  (check-equal? (id x )
(number->string x ...))

(test-it number->string* number->string**)

(define iterations 1000)

(define-syntax-rule (time-it number-to-convert id ...)
 (begin
   (begin
 (collect-garbage)
 (time
  (for ([x (in-range iterations)])
   (id number-to-convert ...))

(time-it 123 number->string number->string* number->string**)
(time-it 123456 number->string number->string* number->string**)
(time-it 123456789 number->string number->string* number->string**)

-- 
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] Are the order of hash-keys and hash-values equivalent?

2016-12-31 Thread David Storrs
On Fri, Dec 30, 2016 at 11:52 PM, Ben Greenman
 wrote:
>
> On Fri, Dec 30, 2016 at 10:45 PM, David Storrs 
> wrote:
>>
>>
>> Can I assume that the elements of keys are in the same order as are
>> the elements of vals?
>
>
> No, because `hash-keys` and `hash-values` do not specify an order.

Got it.  I thought that might be the answer, but I wanted to check.
Perl doesn't specify an order either, although it does specify that
the order is the same for both keys and values.  It would have been
convenient if that had been the case in Racket as well but, as you
say, there are more Racket-ish ways to handle the issue.


>
> Maybe you want `hash->list`, or `in-hash` ?
>
> #lang racket
>
> (define (hash-split h)
>   (for/lists (keys vals) ([(k v) (in-hash h)])
> (values k v)))
>
> (define h (make-immutable-hash '((a . 1) (b . 2) (c . 3
>
> (define-values [keys vals] (hash-split h))
>
> (equal? (first vals) (hash-ref h (first keys)))
> (equal? (second vals) (hash-ref h (second keys)))
> (equal? (third vals) (hash-ref h (third keys)))
>

-- 
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] Conseil

2016-12-31 Thread David Storrs
Seconding the suggestion for racket-mode.  Great job, Greg.

On Sat, Dec 31, 2016 at 6:32 AM, Jens Axel Søgaard
 wrote:
> You can edit Racket programs in for example Emacs or Sublime.
> Use the command   racket   in a terminal to run the program.
> Some editors have special modes for editing racket.
> See
> https://www.youtube.com/watch?v=QWiteH8PARQ
> https://github.com/greghendershott/racket-mode
>
> /Jens Axel
>
>
> 2016-12-31 7:44 GMT+01:00 Masto Fine :
>>
>> Comment editer un prigramme drracket dans une fenetre media
>>
>> --
>> 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.
>
>
>
>
> --
> --
> Jens Axel Søgaard
>
> --
> 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.


Re: [racket-users] Conseil

2016-12-31 Thread Jens Axel Søgaard
You can edit Racket programs in for example Emacs or Sublime.
Use the command   racket   in a terminal to run the program.
Some editors have special modes for editing racket.
See
https://www.youtube.com/watch?v=QWiteH8PARQ
https://github.com/greghendershott/racket-mode

/Jens Axel


2016-12-31 7:44 GMT+01:00 Masto Fine :

> Comment editer un prigramme drracket dans une fenetre media
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

-- 
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] Conseil

2016-12-31 Thread Jens Axel Søgaard
What do you mean by "fenetre media"?

/Jens Axel


2016-12-31 7:44 GMT+01:00 Masto Fine :

> Comment editer un prigramme drracket dans une fenetre media
>
> --
> 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.
>



-- 
-- 
Jens Axel Søgaard

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