[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] [PATCH] Speed up gpsfake.
From: |
Beat Bolli |
Subject: |
Re: [gpsd-dev] [PATCH] Speed up gpsfake. |
Date: |
Thu, 17 May 2012 21:43:12 +0200 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
Hi Terje
On 17.05.12 20:35, Terje Mathisen wrote:
> Beat Bolli wrote:
>> By advancing the twirly baton only each 11th line, the whole
>> regress-driver run is sped up by 7% when run over SSH.
>
> The idea is good, but I cringe when I see the implementation! :-)
>
>> + elif self.count % 11 == 0:
>> self.stream.write("-/|\\"[self.count % 4])
>> self.stream.write("\010")
>> - self.stream.flush()
>> + self.stream.flush()
>> self.count = self.count + 1
>
> The "count % 11" operation is _very_ expensive you know, best case it
> will be implemented as a reciprocal multiplication plus
> back-multiplication (via shift&add) and subtraction, but still taking 10
> cycles or so.
>
> If implemented as a regular DIV operation we're talking 20-40 cycles.
>
> The effect is of course to run the baton _backwards_, at a rate which is
> 1:11 of the original one. If you had used % 13 it would still be going
> forward, but I agree this doesn't really matter. :-)
>
> OTOH, what's wrong with something like this:
>
> elif self.count & 15 == 0:
> self.stream.write("-/|\\"[(self.count >> 4) & 3])
>
> I.e. run at 1:16, with zero mul or div operations?
Wow, I didn't think my patch would get such scrutiny ;-)
Your version would of course be even faster, but as I explained in the
commit message, the main problem with the original implementation
(before my patch) was the relatively frequent flush() that causes
sending a new SSH packet. This is an I/O-bound problem, not a CPU-bound
one ;-)
At least I thought of using a reduction factor that has no common
divisors with the number of baton states...
Beat
--
mail: echo '<address@hidden>' | tr -d '[A-S]'
pgp: 0x506A903A; 49D5 794A EA77 F907 764F D89E 304B 93CF 506A 903A
gsm: 4.7.7.6.0.7.7.9.7.1.4.e164.arpa
icbm: 47.0452 N, 7.2715 E
"It takes love over gold, and mind over matter" -- Dire Straits
signature.asc
Description: OpenPGP digital signature