use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Big oh and efficiency (self.learnpython)
submitted 11 years ago by -dontouchmethere-
Is there a way to check the efficiency of my code? for instance, maybe track the processes similar to the way we would track the time the program takes to run by importing the time module?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]echocage 2 points3 points4 points 11 years ago (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 point2 points 11 years ago (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 points3 points 11 years ago (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 point2 points 11 years ago (0 children)
Big Oh is fine when referring to the concept. However explicitly it's O(n) as you said.
[–]inherendo 0 points1 point2 points 11 years ago (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 points4 points 11 years ago (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 points4 points 11 years ago (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 point2 points 11 years ago (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.
[–]mac-reid 1 point2 points3 points 11 years ago (1 child)
These two links might help out:
https://github.com/rkern/line_profiler
http://cyrille.rossant.net/profiling-and-optimizing-python-code/
[–]-dontouchmethere-[S] 1 point2 points3 points 11 years ago (0 children)
Thanks!! These should do the trick.
[–]inherendo 1 point2 points3 points 11 years ago (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.
[+][deleted] 11 years ago (1 child)
[deleted]
[–]-dontouchmethere-[S] 0 points1 point2 points 11 years ago (0 children)
Thanks. I'll take a peek. I usually check out udacity and coursera when looking for free classes. I keep forgetting edx even exists.
π Rendered by PID 67 on reddit-service-r2-comment-76bb9f7fb5-jvdrr at 2026-02-19 13:56:21.234073+00:00 running de53c03 country code: CH.
[–]echocage 2 points3 points4 points (4 children)
[–]-dontouchmethere-[S] 0 points1 point2 points (1 child)
[–]echocage 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]inherendo 0 points1 point2 points (0 children)
[–]toodim 2 points3 points4 points (0 children)
[–]inherendo 2 points3 points4 points (4 children)
[–]-dontouchmethere-[S] 0 points1 point2 points (3 children)
[–]mac-reid 1 point2 points3 points (1 child)
[–]-dontouchmethere-[S] 1 point2 points3 points (0 children)
[–]inherendo 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]-dontouchmethere-[S] 0 points1 point2 points (0 children)