Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
& vs %
#1
which is better:
    foo = bar % 256
or:
    foo = bar & 255
???

i just benchmarked them for speed.  the 2nd is slightly faster in python3.5.2.  in a loop of 1000000000 times, it was about 89.36 seconds for the 1st one to 81.53 seconds for the 2nd one, on my laptop.  is that enough reason to use the latter?  the code i will putting this in will probably run at most no more than 20 times a day.

i just tried them in python2.7.12 ... 60.12 seconds for the 1st vs. 49.55 seconds for the 2nd.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
& vs % - by Skaperen - Nov-29-2017, 03:40 AM
RE: & vs % - by buran - Nov-29-2017, 07:45 AM
RE: & vs % - by DeaD_EyE - Nov-29-2017, 08:14 AM
RE: & vs % - by Skaperen - Nov-29-2017, 08:27 AM
RE: & vs % - by wavic - Nov-29-2017, 09:37 PM
RE: & vs % - by Skaperen - Nov-30-2017, 01:53 AM
RE: & vs % - by wavic - Nov-30-2017, 02:25 AM
RE: & vs % - by Skaperen - Nov-30-2017, 03:04 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020