Advertisement
Guest User

redefining chrs() in Python3 seems to do the trick

a guest
May 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. >>> cProfile.run('bits_strings(1000, 1000)')
  2.          2004004 function calls in 0.761 seconds
  3.  
  4.    Ordered by: standard name
  5.  
  6.    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  7.         1    0.000    0.000    0.762    0.762 <stdin>:1(bits_strings)
  8.      1000    0.002    0.000    0.758    0.001 <stdin>:1(chrs)
  9.   1001000    0.583    0.000    0.664    0.000 <stdin>:2(<genexpr>)
  10.         1    0.000    0.000    0.762    0.762 <string>:1(<module>)
  11.   1000000    0.081    0.000    0.081    0.000 {built-in method builtins.chr}
  12.         1    0.000    0.000    0.762    0.762 {built-in method builtins.exec}
  13.         1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
  14.      1000    0.003    0.000    0.003    0.000 {method 'getrandbits' of '_random.Random' objects}
  15.      1000    0.092    0.000    0.756    0.001 {method 'join' of 'str' objects}
  16.  
  17.  
  18. >>> def chrs(bits, len_string):
  19. ...     return ''.join(chr((bits >> (8*offset)) & 0xff) for offset in range(len_string))
  20. ...
  21. >>> cProfile.run('bits_strings(1000, 1000)')
  22.          1004005 function calls in 0.178 seconds
  23.  
  24.    Ordered by: standard name
  25.  
  26.    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  27.         1    0.000    0.000    0.755    0.755 <stdin>:1(bits_strings)
  28.      1000    0.002    0.000    0.751    0.001 <stdin>:1(chrs)
  29.      1001    0.001    0.000    0.755    0.001 <stdin>:2(<genexpr>)
  30.         1    0.000    0.000    0.756    0.756 <string>:1(<module>)
  31.   1000000    0.080    0.000    0.080    0.000 {built-in method builtins.chr}
  32.         1    0.000    0.000    0.756    0.756 {built-in method builtins.exec}
  33.         1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
  34.      1000    0.003    0.000    0.003    0.000 {method 'getrandbits' of '_random.Random' objects}
  35.      1000    0.092    0.000    0.750    0.001 {method 'join' of 'str' objects}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement