At Sun, 27 Jun 2021 21:36:09 +0300, Bogdan Popa wrote: > While I think the complexity piece is important, I feel like it's worth > pointing out just how much more expensive the allocation -- and its > ramifications, like the resulting GC pressure and CPU cache misses -- is > than one might think. Here's a quadratic version of the code that > avoids allocations: > [...] > On my machine (running Racket CS 8.1), this is faster than the > `call-with-output-string` version I posted earlier by about 50ms.
That doesn't sound right to me. Your program does run fast on my machine, but I think it's because this line doesn't have the intended bad effect: > (string-copy! dst 0 dst 0 len) ;; intentionally performing pointless > ;; work to be n^2 A `string-copy!` like this will eventually use the C library's `memmove`, which apparently (and sensibly) doesn't do anything if the source and destination are the same. Try copying to a `dst2` to get quadratic behavior. -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20210627135005.2f6%40sirmail.smtps.cs.utah.edu.

