Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.physics > #644548
| From | owl <owl@rooftop.invalid> |
|---|---|
| Newsgroups | comp.os.linux.advocacy, sci.physics |
| Subject | Re: Owl's FizBuzGozKaz branches 5 times more often. |
| Date | 2017-08-05 15:40 +0000 |
| Organization | O.W.L. |
| Message-ID | <pq12jbv903ab.h3uu4@rooftop.invalid> (permalink) |
| References | (2 earlier) <ZPednQQM1d-coBjEnZ2dnUU7-emdnZ2d@giganews.com> <pi3abz.3g88x8@rooftop.invalid> <Jeff-Relf.Me@Aug.4--11.07pm.Seattle.2017> <azb3a009ba.38@rooftop.invalid> <Jeff-Relf.Me@Aug.5--1.30am.Seattle.2017> |
Cross-posted to 2 groups.
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Owl ) replied ( to me ):
> > > Moving to 4 primes, it's: [ I reduced your 43 lines to 5 ]
> > >
> > > char *Say[16] = { "%d", "Fiz", "Buz", "FizBuz", "Goz", "FizGoz",
> > > "BuzGoz", "FizBuzGoz", "Kaz", "FizKaz", "BuzKaz", "FizBuzKaz",
> > > "GozKaz", "FizGozKaz", "BuzGozKaz", "FizBuzGozKaz" }; int x = 0 ;
> > > while ( x++ < 100 ) printf(", "),
> > > printf( Say[ 8*!(x%11) + 4*!(x%7) + 2*!(x%5) + !(x%3) ], x );
> >
> > What difference does that make? I can reformat my source and have most
> > of it on one line. Besides, my code runs faster than yours. LALALALA.
> > What you did is make a mess.
>
> Stop lying to yourself,
> I reduced your 43 lines, 74 columns to: 5 lines, 71 columns, indented.
>
> Your FizBuzGozKaz isn't faster ( or slower ) than mine; note:
>
My tests show that it is.
> 1. You branch 5 times more often.
>
The regularity of this pattern means that the CPU's branch
prediction will have no trouble.
> 2. I call one function. You call 16 different functions,
In your latest example, you call printf() twice for each iteration.
> each of which calls another funtion, pushing the stack.
>
All but one of the printfs acts on a string literal. The compiler
could inline them.
> > all you will ever want to do is printf().
>
> Right, UnlessAndUntil you convince me otherwise;
> I won't be holding my breath.
>
I already showed you a good use: 3,5,571,897 don't hit on all four
until you're at about 2.5 million iterations; 3,571,891,1277 don't all
hit until nearly 650 millon iterations. The popups notify you that you
have a hit at a certain level and keep you from having to grep after
every run when you're testing various sets of numbers at various counts:
./foo a b c d 1000
./foo a b c d 10000
./foo a b c d 100000
./foo a b c d 1000000
...
You can keep upping the count until you get a popup. You could easily
make the popup conditional by passing an option in argv, and kill a run
as soon as you get a popup, then run the program again without popups
to get all values without interaction.
Back to sci.physics | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:11 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:47 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:52 -0700
Re: Mozilla ThunderBird. Snit <usenet@gallopinginsanity.com> - 2017-08-04 10:43 -0700
Re: FizzBuzz is a trick question. Snit <usenet@gallopinginsanity.com> - 2017-08-04 11:47 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:51 -0700
Re: I'm the best c coder here. Snit <usenet@gallopinginsanity.com> - 2017-08-04 14:03 -0700
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-04 23:15 +0000
Re: I'm the best c coder here. benj <benj@nobody.net> - 2017-08-04 19:35 -0400
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-05 16:08 +0000
Re: Fabian seldom writes code, much less test it. owl <owl@rooftop.invalid> - 2017-08-05 03:09 +0000
Re: 2 lines, 2^2 states, easily modified to 3^2 states. owl <owl@rooftop.invalid> - 2017-08-05 05:42 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 13:37 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 14:25 +0000
Re: I'm the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 03:22 +0000
Re: I'm _still_ the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 06:12 +0000
Re: Owl's FizBuzGozKaz branches 5 times more often. owl <owl@rooftop.invalid> - 2017-08-05 15:40 +0000
Re: I'm _still_ the best c coder here. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-05 22:16 +0000
Re: I increment things at the _start_ of a loop. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 03:24 +0000
Re: I increment things at the _start_ of a loop. Snit <usenet@gallopinginsanity.com> - 2017-08-06 20:35 -0700
Re: "while ( x++ < 100 )" isn't "obscure". moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 04:59 +0000
Re: I'm the best c coder here. chrisv <chrisv@nospam.invalid> - 2017-08-07 06:59 -0500
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Doomsdrzej <.m@nsn.s> - 2017-08-05 11:52 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-05 09:55 -0700
csiph-web