[dev-context] format() without formatting

Hans Hagen pragma at wxs.nl
Tue Jun 17 13:08:33 CEST 2008

Arthur Reutenauer wrote:
>> this is a bit weird case ... on the one hand you specify %5f and such 
>> but that's ignored i.e. becomes %s so why not use %s in the first place 
>> then
>   Actually, this was precisely my intention: to show that one could use
> the original format string with different formatting requirements (I
> don't know where that format string is going to come from, if Peter is
> going to type or if it's going to be inserted by some lower-level
> function).  But I agree that if the user is going to type it himself,
> he'd better use %s for convenience (Lua is so tolerant anyway).

sure; in this case the %f is deep down in the mkiv code

>> anyway, originally i used %s but when taco and i played with the 
>> converter and did some performance tests we found out that %f is faster 
>> (unless > 6 digits specified)
>   I suppose that when Lua sees a %s format with an argument that is not
> a string, he calls tostring which must be much slower.

i think that for any conversion it has to call a function (take hex) but 
tostring may be costly due to metatable access, also it seems that 
tostring does some stripping


                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
      tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl

More information about the dev-context mailing list