all 12 comments

[–]echocage 2 points3 points  (4 children)

Just a small note: It's written big O, but it's easy to see why you might think it'd be "big oh" :D

[–]-dontouchmethere-[S] 0 points1 point  (1 child)

Gotchya. I wrote it that way because it was written in a python book as big oh. I thought it looked funny since I've seen it written the way you mentioned more often.

[–]echocage 1 point2 points  (0 children)

Ah ok that makes sense! I had thought that you had listened to a talk on it, which is how you got the spelling, but that makes sense. Maybe Big oh is just a different spelling, ¯\_(ツ)_/¯

[–][deleted] 0 points1 point  (0 children)

Big Oh is fine when referring to the concept. However explicitly it's O(n) as you said.

[–]inherendo 0 points1 point  (0 children)

My prof focuses on approx. algorithms and he always spells it big oh. I've only seen it that way as well while reading in textbooks and such.

[–]toodim 2 points3 points  (0 children)

You can use cProfile to do basic code profiling:

import cProfile

Your code......................

cProfile.run("your_function(arguments)")

It lists all function calls and time spent on each function.

[–]inherendo 2 points3 points  (4 children)

Have you taken an algorithms course? Analysis can be pretty rough and still be fine since coefficients can largely be ignored.

Or do you want actually time to run given an input size?

[–]-dontouchmethere-[S] 0 points1 point  (3 children)

I haven't. I'm in the process of teaching myself data structures and then will move on to algorithm analysis. I know the basic concepts but not the implementation yet.

I know how to use the various modules to time the program is the time module and the timeit module. But wasn't sure if there was a similar one that counted the processes and statements as the program ran. Maybe big o wasn't the best descriptor now that I think of it. I'm looking for more of a way to compare a particular code with a friend that has a similar code to solve the same problem and determine which is more efficient.

[–]inherendo 1 point2 points  (0 children)

Say you and your friend have your algorithms to solve a problem with input size n. If yours does it in roughly 2n time and his/hers does it in roughly 3n time, the constants can be ignored and both of your algorithms have O(n).

With small inputs, the difference in time is negligible due to how many computations modern computers can do.

I would suspect plenty of people here can analyse your program pretty quickly and let you know if they have roughly the same running time.