3 ms·
Looking at the tangentially linked qrintf project that H2O uses ( https://github.com/h2o/qrintf https://github.com/h2o/qrintf ), replacing generic sprintf calls
by Shish2k 12y ago
Looking at the tangentially linked qrintf project that H2O uses ( https://github.com/h2o/qrintf https://github.com/h2o/qrintf ), replacing generic sprintf calls with specialised versions for a 10x speed boost - that seems like a brilliant idea, I wonder why it took so long for somebody to think of it?
- chubot 12y agoPeople have thought of it -- there's probably just not that many applications where sprintf is a bottleneck. Especially enough of a bottleneck to justify a code gen tool. The OCaml community, and probably others, have noted that printf is an embedded DSL and treat it as something to be compiled rather than interpreted. http://okmij.org/ftp/typed-formatting/ http://okmij.org/ftp/typed-formatting/ http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.htm... (I have a memory of this being type safe and doing stuff at compile time but I don't see it now) Rust borrows heavily from OCaml, and uses compile time macros for printf and regex, i.e. format! and regex! (the trailing ! means it's a macro that can be further compiled by the compiler). http://doc.rust-lang.org/std/fmt/ http://doc.rust-lang.org/std/fmt/ http://doc.rust-lang.org/regex/regex/index.html http://doc.rust-lang.org/regex/regex/index.html
- deleted 12y ago[deleted]
- Someone 12y agoA quick google gave me https://gcc.gnu.org/ml/gcc/2007-10/msg00073.html https://gcc.gnu.org/ml/gcc/2007-10/msg00073.html, so at least somebody thought of it over 7 years ago. Also, http://www.ciselant.de/projects/gcc_printf/gcc_printf.html#printf_puts_enhancements:url http://www.ciselant.de/projects/gcc_printf/gcc_printf.html#p... shows gcc did something in this area 9 years ago. http://www.cygwin.com/ml/libc-hacker/2001-08/msg00003.html http://www.cygwin.com/ml/libc-hacker/2001-08/msg00003.html indicates gcc had printf optimizations in 2001. I expect there are older examples. qrintf seems to be 'just' a more aggressive version of this. I guess being more aggressive makes sense in applications that do a lot of simple string formatting.
- nly 12y agoOne of the problems with compiling print/scanf is that a lot of the overhead comes from locale handling, which is a runtime variable. Parsing is fairly negligible for short format strings.
- justincormack 12y agoFew applications want locale support. Mostly you want reproducible output.