help-libidn
[Top][All Lists]
Advanced

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

Re: Maybe optimize adapt function in punycode.c (libind & libidn2)


From: Simon Josefsson
Subject: Re: Maybe optimize adapt function in punycode.c (libind & libidn2)
Date: Tue, 19 Nov 2013 16:42:55 +0100
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux)

Igor V Belousov <address@hidden> writes:

> I'm not tested benchmark in c code. I tested function 'adapt' on
> php. this reduces the time of program execution.

What does 'adapt' do?  It seems since these symbols are constants, the C
compiler should optimize it.

/Simon

> I removed several math operation.
>
> base, tmin and tmax it is constant.
>
> base=36
> tmin=1
> tmax=26
>
> delta =delta / ( base - tmin);
> delta =delta / ( 36 - 1);
> delta =delta / (35);
>
> ((base - tmin) * tmax) / 2
>
> ((36 - 1) * 26) / 2= 455
>
>
>
>
> 19.11.2013, 18:02, "Simon Josefsson" <address@hidden>:
>> Igor V Belousov <address@hidden> writes:
>>
>>>  Hi,
>>>  I'm modify code in punycode.c for faster run.
>>
>> Hi.  Thanks for looking at the code.  Can you explain a bit more about:
>>
>> 1) How much faster is the code, in what kind of benchmark?
>>
>> 2) How the change is guaranteed to not change semantics?  Where do the
>> magic values 455 and 35 come from?
>>
>> /Simon
>>
>>>  --- punycode_old.c      2013-10-29 11:13:31.000000000 +0400
>>>  +++ punycode.c  2013-10-29 11:13:43.000000000 +0400
>>>  @@ -146,12 +146,12 @@
>>>     /* delta >> 1 is a faster way of doing delta / 2 */
>>>     delta += delta / numpoints;
>>>
>>>  -  for (k = 0; delta > ((base - tmin) * tmax) / 2; k += base)
>>>  +  for (k = 0; delta > 455; k += base) //faster way
>>>       {
>>>  -      delta /= base - tmin;
>>>  +      delta /= 35;//faster way
>>>       }
>>>
>>>  -  return k + (base - tmin + 1) * delta / (delta + skew);
>>>  +  return k + base  * delta / (delta + skew);// base - tmin + 1 =
>>> base - 1 + 1
>>>   }
>>>
>>>   /*** Main encode function ***/
>>>
>>>  Sorry bad English.
>>>  Igor V Belousov.
>>>
>>>  _______________________________________________
>>>  Help-libidn mailing list
>>> address@hidden
>>>  https://lists.gnu.org/mailman/listinfo/help-libidn
>
> _______________________________________________
> Help-libidn mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-libidn



reply via email to

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