Displaying a string in guile has the speed:
> (define p (open-file "/dev/null" "w"))
> (define x (make-string 100000000 #\a))
> ,time (begin (display x p) 1)
1.015054s real time, 1.014577s run time. 0.000000s spent in GC.
That's about 100MByte of data pushed out in 1 second. Okay, but what if I noticed that I have a string that has in 99% of the cases ascii values and only some spurious latin1 characters like inserting a line in Swedish now and when we should be able to move along as it is just ascii and basically copy the string. But you need to check of non asciiness, so just not a simple memmove then or? Here comes the splendid thingie. There is a nice SIMD instruction that can check 16 bytes for asciness at a time and with that we get the following speed,
> (use-modules (ice-9 write))
> (define p (open-file "/dev/null" "w"))
> (define x (make-string 100000000 #\a))
> ,time (begin (display x p) 1)
0.028125s real time, 0.028080s run time. 0.000000s spent in GC.
Yeah a humble 40X speed and you are transferring about 4GB/s via this display, maybe not so practical speed if you out it to a network with 100MBit/s, but we may be talking about a byte vector port and then this speed is, yes, absolutely spot on.
Okey the next step is to do similar magic to writing latin1 string compared to displaying them, this means that some characters needs to be quoted like \n,\,"" and this is now the result for printing a string of these special characters,
For guile's internal write:
> (define p (open-file "/dev/null" "w"))
> (define x (make-string 100000000 #\a))
> ,time (begin (write x p) 1)
6.070533s real time, 6.069210s run time. 0.000000s spent in GC.
For the new library,
> (use-modules (ice-9 write))
> (define p (open-file "/dev/null" "w"))
> (define x (make-string 100000000 #\a))
> ,time (begin (write x p) 1)
;; 0.034932s real time, 0.034690s run time. 0.000000s spent in GC.
That's a nice 200X speedup!