help-gawk
[Top][All Lists]
Advanced

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

Re: How to Generate a Long String of the Same Character


From: Neil R. Ormos
Subject: Re: How to Generate a Long String of the Same Character
Date: Tue, 20 Jul 2021 22:42:11 -0500 (CDT)

Wolfgang Laun wrote:
> [Neil R. Ormos wrote:]
>> Wolfgang Laun wrote:

>>> The results for the four versions:
>>>  *rec*   0m1,436s
>>>  *dbl*   0m2.322s
>>>  *rpt*  0m13.543s
>>>  *sub*  0m27.290s

>> I was a little surprised that the recursive
>> algorithm was so much faster in Wolfgang's tests.

> [...] You need to add
>     if( n == 0 ) return "";
> as the first instruction in neil. [...]

I ran the tests again using three different Gawk
versions: 3.1.6, 4.1.4, and 5.1.0. Numbers shown
are the mean elapsed times in seconds from 20
successive runs.  (The gawk 3.1.6 tests were run
on a slower machine than I used for the other two;
I don't know how much of the difference is due to
CPU speed and how much might be due to
improvements in Gawk or other factors.)

In the test of building a billion-character
string, Wolfgang's recursive algorithm is much
faster than my doubling method in Gawk 3.1.6.
OTOH, the two methods perform similarly in Gawk
4.1.4 and 5.1.0.

In Wolfgang's tests of building many shorter
strings, Wolfgang's recursive algorithm is slower
than my doubling method in all three versions of
Gawk, but the difference is much more pronounced
in the newer Gawk versions, with run times on the
order of 80 percent longer.  Adding the if
statement to my doubling function (Neil-Double-B)
so it correctly handles 0 requested repetitions
slowed performance by a couple of percent on
Wolgang's shorter-string tests.  Gawk 5.1.0 seems
to be a smidge slower than 4.1.4 on the shorter
string tests.  I am unaware of what differences
there may have been in build options among the
two.


Task: Build a String of Length 10^9 Chars

Gawk-Version        3.1.6  4.1.4  5.1.0
==================  =====  =====  =====
Neil-Double-A       3.295  0.795  0.791
Neil-Double-B       3.297  0.793  0.792
Wolfgang-Recursive  1.891  0.796  0.803
==================  =====  =====  =====


Task: Wolfgang's Tests of Building Many Shorter Strings

Gawk-Version        3.1.6  4.1.4  5.1.0
==================  =====  =====  =====
Neil-Double-A       4.408  0.891  0.997
Neil-Double-B       4.482  0.905  1.016
Wolfgang-Recursive  5.153  1.748  1.805
==================  =====  =====  =====


> But I still get results where your non-recursive
> function is somewhat slower than my recursive
> one.  [...]

Perhaps Jose Buendia is hiding in one of our
computers.



reply via email to

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