[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is fprintf slow?

From: Ted Harding
Subject: Re: Is fprintf slow?
Date: Mon, 27 Mar 1995 23:16:03 +0200 (BST)

> I am surprised that this takes 43 seconds on your system.  On my
It's a slow Joe, John!

> SPARCstation 2, it only takes about 5.  It takes much less if I set
> the variable save_precision to 5 instead of the default 17.
> One possiblity that that would be easy to implement and might cover
> many uses for something like this would be to introduce some new
> format specifiers that work on matrices.  For example, 
>   printf (" %8.5G", m)
> might print all elements of the matrix m with the format " %8.5g",
> separating rows with new lines.
> However, this would have the limitation of not allowing you to specify
> different formats for different columns in a matrix.

Granted the limitation, this would be very useful for this case, which
very commonly occurs. I doubt the limitation would be a /systematic/
problem because if you intend to apply different formats to different
columns you are likely to know how many columns there are and can
write a format string for the entire row.

The most likely exception to what I just said is the case of repetition
of formats across the column (e.g. for integer, real, integer, real, ... )

Maybe it's worth thinking about a FORTRAN-style repetition of
format pattern, like

printf("  %4.0f %7.4f", M)d i

where the pattern would be applied across the matrix M, two columns at a
time in this case, until (as they used to say) "the DO is exhausted".
Maybe if there's a logical trap in this, perhaps a special format
character %& (say) meaning "this format string is repeatable" can be
introduced, so the above would be

printf("%&  %4.0f %7.4f", M).

Before you know what's happening, people will be asking for

printf("%2.0f %2.0f %{%&  %4.0f %7.4f%}", M)

(also FORTRANnish, if I remember right).

Thanks for the reply.
Ted.                                     (address@hidden)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]