python - Difference between two snippets of code? -


is there difference in terms of performance in doing this:

for in range(t):         arr = [int(arr_temp) arr_temp in input().strip().split(' ')] 

and this:

for in range(t):     arr = input().strip().split(' ')     arr = list(map(int, arr)) 

if yes, better?

according ipython's %timeit function, map bit faster:

in [16]: s = ' '.join(map(str, range(1000)))  in [17]: %timeit [int(c) c in s.split()] 10000 loops, best of 3: 171 µs per loop  in [18]: %timeit list(map(int, s.split())) 10000 loops, best of 3: 138 µs per loop 

tested ipython 1.2.1 , python 3.4.3 , different input sizes (range(1000), range(10), , range(100000)).

of course, interesting question is: part of code slowing down program (assuming that's why asking, , not out of pure curiosity). compared to, e.g., reading input (from file, presume?), or doing calculations data, might pretty insignificant.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -