Computer Science, asked by deepalijaingarg, 8 months ago

i have observed that python is too much slower than c++'s compiled program. Thats why i need this code's translation to c++ as this code processes on a very big file(2.5 gb) and it ends in like days. your answer would be very helpful to me. (also, any suggestions for further improvement in speed or anything would helpful) INFORMATION THAT COULD BE HELPFUL:- - The file contains prime numbers until 5,000,000,000 - there is an "enter" between each number - this program tries to compress/encrypt the file (though it has very narrow application; i know) - first this program makes a string and then converts it in multiples of 8 (you will understand its use after reading the below algorithm) - it uses conversion to byte array. ALGORITHM FOR THE COMPRESSION/ENCRYPTION MENTIONED ABOVE:- 1. Make a string 2. If a number is present (ie. it is prime) write 1 instad of it in the string 3. Else write 0 to the string 4. Convert the string size in multiples of 8 and then convert it to bytearray to write it to the file 5. Write it to the file opened in binary format here is the code:- def is_integer(n): try: float(n) except ValueError: return False else: return float(n).is_integer() file = open("../create/prime/prime.txt", "r") i = 0 output = "" while True : inp = file.readline() if is_integer(inp): inp = int(inp) else: break while i < inp: i+=1 output +="0" output+="1" i+=1 print(i-1) lenrem = (len(output) % 8 )+1 for j in range(0,lenrem): output+="0" ab = bytearray(int(output[x:x+8], 2) for x in range(0, len(output), 8)) fileo = open("out.bin", "wb") fileo.write(ab) fileo.close() file.close() i have tried this out and in it i got stuck up at three points mainly:- - exeption handling in the `is_integer()` function - conversion to bytearray from string - writing this bythearray to binary file any answers answering only these questions would also be helpful to me to convert rest of the code myself. Thank you for your valuable time.

Answers

Answered by iambhaskar6258
0

I a unable to type....so if u Search In Google U will get The answer..sry............plzzz.........................Any one can Judge me

Similar questions