+ 3
Built-in function process time
I wonder does built-in function sort of like .Sort in c# and .max arr in python giving you same processing time like 0(n) same like you do in DIY (do it yourself) method?
5 Answers
+ 3
You can test these things by yourself, measuring performance time with tools like (Python) time.timeit or time.perf_counter.
I once made an iterative binary search and wanted to see if it was as quick as the keyword 'in'. Well, it was quick - but not quite as quick.
The built-in stuff (again Python) is written in C and optimized. You write your own methods in Python, so there'll be always a bit of overhead you can't control (unless you write your own extensions).
Probably, if there is a built-in solution in a higher language, it will frequently be the best choice.
But if you cook up performance tester codes here, let me know, those are always fun to see. :)
+ 3
I'm not totally fit in the O notation stuff, but it is a relative measurement, isn't it?
If you code a specific algorithm in two variations, then the algorithm may in absolute terms run more quickly, because it uses built-in tools, but the steps to get there would be the same, because it's the same algo.
Like two persons walking 100 steps, but one has slighly longer legs.
It's the same algo (put one foot in front of each other, always keeping one foot on the ground) so it would have the same O-notation, but the longer legs give an advantage anyway.
I hope this is 1 correct and 2 understandable.
+ 1
Python is definitely convenient, but it is slower than for example C. The convenience comes at a price.
When performance speed isn't the most important consideration, then a language like Python may allow you to write programs more quickly and easily.
But that's practical issues and hasn't much to do with O notation stuff in my opinion (unless you compare the inner workings of the languages themselves).