2

I think the question is self explanatory.
If I want to execute a program that takes an input from a file, will it execute faster if I import and use sys library rather than fileinput or there will be no difference?

Rory Daulton
  • 20,571
  • 5
  • 39
  • 47
Thomas
  • 49
  • 1
  • 9

1 Answers1

2

Reading and writing to a disk is thousands of times slower than accessing memory (and that's much slower than accessing the CPU cache or just executing instructions), so it's unlikely that there would be a significant difference unless the library is amazingly inefficient. It's also unlikely that this would be the bottleneck if your program, but you should profile it if you're still concerned.

Community
  • 1
  • 1
Brendan Long
  • 51,248
  • 19
  • 139
  • 179