DEV Community

Discussion on: Which Programming language is faster at reading?

Collapse
 
cicirello profile image
Vincent A. Cicirello

Interesting comparison. Keep in mind though that it mostly just compares time to read from a file. For other tasks, you will find rather different results. For example, Python's "surprising" 2nd place performance, only slightly behind C, isn't actually that surprising for this task. I would expect the Python case to be only marginally behind C as you saw, and ahead of the others. Why? Almost all of the cost of this task is in the file i/o, and in this case in the calls to Python's f.read, which the Python interpreter implements natively in C (link to source code). So the small time difference between the C and Python versions comes from the rest of the benchmark task, which is little compared to the overhead of the file i/o portion.

Your example demonstrates that Python can be very fast if the task at hand spends a lot of time in functions that the Python library implements natively.

If you really want to compare speed of languages, you need to use a variety of benchmark tasks. Each language may excel in different areas. So you want to look at performance over a diverse set of tasks.

Collapse
 
fredysandoval profile image
Fredy Sandoval

I agree, thanks for the comment.