Converting string to int is too slow

后端 未结 3 1703
萌比男神i
萌比男神i 2021-01-12 00:28

I\'ve got a program that reads in 3 strings per line for 50000. It then does other things. The part that reads the file and converts to integers is taking 80% of the total r

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 01:02

    I can't reproduce this at all.

    I have generated a file of 50000 lines, containing three random numbers (two ints, one float) on each line, separated by spaces.

    I then ran your script on that file. The original script finishes in 0.05 seconds on my three-year-old PC, the script with the uncommented line takes 0.15 seconds to finish. Of course it takes longer to do string to int/float conversions, but certainly not at the scale of several seconds. Unless your target machine is a toaster running embedded Windows CE.

提交回复
热议问题