0

I was working on a Python program, and somewhere in the code I have to convert some heavy data to a string. But then I ran some tests to see what would be the best approach. I thought of two ways and I made some tests using timeit:

tests

My question is: why string formatting was faster than calling str()?

NickS1
  • 496
  • 1
  • 6
  • 19

1 Answers1

2

If you use the disassemble module on both f-string and str() you'll see str() calls an extra function and function calls are very time intensive!