Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
raw byte of integer
#1
Hello!
I am brand new, so bear with me. I am trying to do a specific polynomial of crc32 in py and that seems to be working but its horribly slow (c++ does 2 million of these crc32s + an md5 in 0.4 or less seconds, java did it in 1.5 sec, and python is taking 6-7 sec for just 1M crcs!!). My testing indicates that the shift (<< 24) operator is the main issue, and I tried division (it was no good) and am now looking at ctypes (I am proficient at c & c++) to see if I can just directly access the offending byte.

I want to take a ctypes pointer to a 4 byte integer and get the third byte (as unsigned byte).
I have been messing with the cast function and the pointers for a couple of hours now and can't seem to nail down the syntax (in spite of similar but not quite what I want examples online).

i = c_uint(12345678)
cast(i, POINTER(c_byte*4)())

Can anyone direct me, or am I going down the wrong approach, and if so, is there a fast way to do x >> 24 (and similar) in python? I know I can call my C code but we don't use it at my company, no one much knows it and its marked avoid at all costs (annoying, but that is how it is). I am not expecting the 0.4 but would love to get cut it on down to at least java's speeds.
Reply


Messages In This Thread
raw byte of integer - by jonnin - Jul-21-2019, 03:08 PM
RE: raw byte of integer - by jonnin - Jul-21-2019, 07:31 PM
RE: raw byte of integer - by scidam - Jul-21-2019, 11:25 PM
RE: raw byte of integer - by jonnin - Jul-22-2019, 12:49 AM
RE: raw byte of integer - by jonnin - Jul-22-2019, 03:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,573 Sep-18-2020, 10:10 PM
Last Post: tienttt
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 31,711 Feb-08-2020, 06:58 PM
Last Post: karkas
  4 byte hex byte swap from binary file medievil 7 22,120 May-08-2018, 08:16 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

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