Built-in function process time | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

28th Dec 2019, 11:05 PM
Fahmi Herlambang
Fahmi Herlambang - avatar
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. :)
28th Dec 2019, 11:16 PM
HonFu
HonFu - avatar
+ 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.
28th Dec 2019, 11:32 PM
HonFu
HonFu - avatar
+ 1
HonFu ty for answer, this question based on someone gave python code with loops but still have built in function there and claims its 0(n), so i wonder does built in function not giving you an any N times.
28th Dec 2019, 11:25 PM
Fahmi Herlambang
Fahmi Herlambang - avatar
+ 1
HonFu yes ty me understand, im totally new in python so because of his code i just assuming maybe python have very good built in function (sort of instant access array) so i discussing it here 😅
28th Dec 2019, 11:41 PM
Fahmi Herlambang
Fahmi Herlambang - avatar
+ 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).
28th Dec 2019, 11:44 PM
HonFu
HonFu - avatar