Re: *scanf efficiency for patterns

Discussion in 'C Programming' started by Malcolm, Aug 27, 2003.

  1. Malcolm

    Malcolm Guest

    "Christopher Benson-Manica" <> wrote in message
    >
    > How efficient are the *scanf functions when used for pattern matching?
    > Specifically, is something like
    >

    The real answer is "probably efficient enough for it not to matter".
    Typically a program will only process a relatively small quantity of
    strings, and processing time will be dwarfed by time taken to input the
    string.

    scanf() is a general-purpose routine, so it is probably possible to beat it
    by coding a dedicated function. However since scanf() is in the standard
    library it may well be written in native machine code and heavily optimised,
    an investment which would be expensive for a one-off, unless of course it is
    absolutely vital to squeeze the last drop of performance in that particular
    function.
     
    Malcolm, Aug 27, 2003
    #1
    1. Advertisements

  2. Malcolm

    Eric Sosman Guest

    Malcolm wrote:
    >
    > "Christopher Benson-Manica" <> wrote in message
    > >
    > > How efficient are the *scanf functions when used for pattern matching?
    > > Specifically, is something like
    > >

    > The real answer is "probably efficient enough for it not to matter".
    > Typically a program will only process a relatively small quantity of
    > strings, and processing time will be dwarfed by time taken to input the
    > string.
    >
    > scanf() is a general-purpose routine, so it is probably possible to beat it
    > by coding a dedicated function. However since scanf() is in the standard
    > library it may well be written in native machine code and heavily optimised,
    > an investment which would be expensive for a one-off, unless of course it is
    > absolutely vital to squeeze the last drop of performance in that particular
    > function.


    An anecdote for the "You never can tell" file:

    One C implementation I ran into some years ago did just
    as Malcolm said: It used hand-crafted assembly language for
    many of the library functions. The result? Programs ran
    *slower* than with naive pure-C implementations!

    The architecture featured a fairly rich set of string-
    bashing instructions, and the library implementors used them:
    after all, loading a few registers and executing one machine
    instruction must be faster than an ordinary loop, right?
    Alas, the particular machine at hand was based on a cost-
    reduced design that didn't implement the entire instruction
    set in hardware, but instead provided trap-and-emulate code
    for the missing instructions ... I achieved an *eightfold*
    speedup in our PostScript generation by substituting plain-C
    implementations of *printf() for the "optimized" versions.

    Moral: Measure, measure, measure!

    --
     
    Eric Sosman, Aug 27, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Krone

    perl efficiency -- fastest grepping?

    Bryan Krone, Nov 5, 2004, in forum: Perl
    Replies:
    1
    Views:
    1,658
    Jim Gibson
    Nov 8, 2004
  2. Trevor Hartman

    dataset efficiency question

    Trevor Hartman, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    493
    Trevor Hartman
    Jul 3, 2003
  3. Joseph D. DeJohn

    Custom Paging Efficiency

    Joseph D. DeJohn, Aug 6, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    478
    S. Justin Gengo
    Aug 6, 2003
  4. MC D
    Replies:
    4
    Views:
    660
    Big D
    Nov 18, 2003
  5. =?Utf-8?B?R2VvcmdlIER1cnpp?=

    Regex Efficiency Q - Manipulating Html

    =?Utf-8?B?R2VvcmdlIER1cnpp?=, Feb 28, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    368
    =?Utf-8?B?R2VvcmdlIER1cnpp?=
    Feb 28, 2004
  6. crichmon
    Replies:
    4
    Views:
    703
    Mabden
    Jul 7, 2004
  7. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    4,328
    those who know me have no need of my name
    Apr 3, 2006
  8. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    978
    Richard Bos
    May 2, 2006
Loading...