tag:blogger.com,1999:blog-11149365.post343630742352801845..comments2024-03-23T04:34:59.089+00:00Comments on Go deh!: bit twiddling extrasPaddy3118http://www.blogger.com/profile/06899509753521482267noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-11149365.post-33206792353668198522007-07-03T00:02:00.000+01:002007-07-03T00:02:00.000+01:00Firstly, is 0 considered a power of two for your p...Firstly, is 0 considered a power of two for your purposes?<BR/><BR/>Second, isn't another definition of a power of two a number which, when the lowest bit is cleared, results in 0? Perhaps x & (x - 1) is a quicker test?Ralph Corderoyhttps://www.blogger.com/profile/13140975971019765573noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-8608021145461751122007-07-02T21:51:00.000+01:002007-07-02T21:51:00.000+01:00using a generator syntax instead of list-comprehen...using a generator syntax instead of list-comprehension should make a difference<BR/><BR/>list_of_powers = (x**2 for x in range(32))<BR/><BR/>on my computer (Pentium 4 2.0Ghz), where set-lookup2 and list-comparison2 use the generator syntax:<BR/><BR/>float math is_power_of_2: 2.86237287521<BR/>bit-twiddling is_power_of_2: 0.939764976501<BR/>set-lookup is_power_of_2: 0.940165042877<BR/>set-lookup2 is_power_of_2: 0.871818065643<BR/><BR/>float math next power of 2: 3.69351601601<BR/>bit-twiddling next power of 2: 2.42883086205<BR/>list-comparison next power of 2: 3.53486704826<BR/>list-comparison2 next power of 2: 0.833928108215<BR/><BR/>the difference between set-lookup and set-lookup2 isn't consistent between runs.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11149365.post-17556778169224671002007-07-02T15:14:00.000+01:002007-07-02T15:14:00.000+01:00Paddy:I used an Intel Core 2 Duo MacBook for the t...Paddy:<BR/><BR/>I used an Intel Core 2 Duo MacBook for the tests.<BR/><BR/>Regarding Crunchy, I can't point you to some relevant documentation (yet). You already have mentioned the basic link; download the <B>alpha</B> version and start crunchy.py, then type<BR/><BR/>crunchy.no_markup = 'editor'<BR/><BR/>at the interpreter prompt (the default is "interpreter"), click on the "tests" link in the text above, then on the "loading arbitrary tutorials" link. You can then enter the url of your blog and have fun.<BR/><BR/>I'm hoping that we'll have a non-alpha release of version 0.9 soon, with proper documentation of all the new features.André Robergehttps://www.blogger.com/profile/08131391818998844540noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-21724115875947253162007-07-02T14:16:00.000+01:002007-07-02T14:16:00.000+01:00As I had expected, psyco optimizes the bit-twiddli...As I had expected, psyco optimizes the bit-twiddling version to an enormous degree:<BR/><BR/>Non-psyco runs:<BR/>float math is_power_of_2: 3.45202616534<BR/>bit-twiddling is_power_of_2: 1.96388256049<BR/>set-lookup is_power_of_2: 0.6184283198<BR/><BR/>float math next power of 2: 4.55189640024<BR/>bit-twiddling next power of 2: 2.11398962717<BR/>list-comparison next power of 2: 3.02703835264<BR/><BR/>With pysco:<BR/>float math is_power_of_2: 4.00380746715<BR/>bit-twiddling is_power_of_2: 0.0121230491585<BR/>set-lookup is_power_of_2: 0.975068339691<BR/><BR/>float math next power of 2: 5.06961331678<BR/>bit-twiddling next power of 2: 0.0159525861527<BR/>list-comparison next power of 2: 3.34381911668arkaneshttps://www.blogger.com/profile/06254628778286143065noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-19492867253446914122007-07-02T07:55:00.000+01:002007-07-02T07:55:00.000+01:00On the changes to the order of timings, I should n...On the changes to the order of timings, I should note that I am using an AMD Turion64 notebook - maybe André is using an Intel chip?<BR/><BR/>- Paddy.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-16289975058337225882007-07-02T07:28:00.000+01:002007-07-02T07:28:00.000+01:00André, can you post a link to documentation on how...André, can you post a link to documentation on how you can run code from just a URL using <A HREF="http://code.google.com/p/crunchy/" REL="nofollow">Crunchy</A>? I have been watching crunchy development posts, had tried out an early version but this ability is new to me.Paddy3118https://www.blogger.com/profile/06899509753521482267noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-38265524146300872752007-07-02T00:14:00.000+01:002007-07-02T00:14:00.000+01:00As a test, I just loaded your blog page using a ne...As a test, I just loaded your blog page using a new feature of the alpha version of crunchy[*] on my computer and found the bit-twiddling to be the fastest by a smidgen:<BR/><BR/>float math is_power_of_2: 2.05480490349 bit-twiddling is_power_of_2: 0.614713742749 set-lookup is_power_of_2: 0.635365676879 float math next power of 2: 2.62028308706 bit-twiddling next power of 2: 1.44359330406 list-comparison next power of 2: 1.71020391571<BR/><BR/>[*] All I had to do is copy the url from your blog and the code was loaded ready to be executed. If you want to know how to do this, feel free to email me.André Robergehttps://www.blogger.com/profile/08131391818998844540noreply@blogger.comtag:blogger.com,1999:blog-11149365.post-88485344360858690462007-07-01T23:06:00.000+01:002007-07-01T23:06:00.000+01:00Interesting results, thanks! The next_power_of_2 f...Interesting results, thanks! The next_power_of_2 function has linear performance though. I wonder if it can be done in constant time...Anonymousnoreply@blogger.com