[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to Generate a Long String of the Same Character
From: |
Wolfgang Laun |
Subject: |
Re: How to Generate a Long String of the Same Character |
Date: |
Wed, 21 Jul 2021 06:40:11 +0200 |
We've been hunting a phantom. -- I have hacked 5.1.0, boldly setting
gawk_mb_cur_max = 1 in main.c (instead of the configured value of 6).
And now:
$time ~/Downloads/gawk/gawk-5.1.0/gawk -f srepNeil.awk
MB_CUR_MAX = 1
0:00:01.130
$ time ~/Downloads/gawk/gawk-5.1.0/gawk -f srepRec.awk
MB_CUR_MAX = 1
0:00:01.892
>From a comment in main.c: "[MB_CUR_MAX] is tested *a lot* in many
speed-critical places in gawk." length() is one of these places.
Wolfgang
On Wed, 21 Jul 2021 at 05:42, Neil R. Ormos <ormos-gnulists17@ormos.org>
wrote:
> 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.
>
>
--
Wolfgang Laun