[racket] Performance difference write, display, print and pretty-print

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Sat Aug 25 22:04:58 EDT 2012

I pretty-printed a data structure to a file to analyse it, and it
seemed to take a long time to print so I did a timing comparison
between write, display, print and pretty-print using the same data
which was a vector of lists of structs. The structs were small  4
numbers and two very short lists (2 or 3 members).   There were about
27000 lines  in the pretty-printed file.

The timing results for write, display, print and pretty-print this
data structure was:
write         cpu time: 188 real time: 232 gc time: 0
display      cpu time: 328 real time: 324 gc time: 78
print          cpu time: 10593 real time: 10585 gc time: 218
pretty-print cpu time: 15288 real time: 15687 gc time: 547

Why this big difference between the performance of write and display
to print and pretty-print.  The performance difference (cpu time)
between write and pretty-print is 82 to 1.

Harry Spier

Posted on the users mailing list.