1.5 seconds seems fine at first glance, but the nature of my project is such that I will need to run this particular method hundreds or even thousands of times. I see that the total time for this function is 1.584 seconds, which seems pretty good, right? Only two seconds? You can wait for two seconds for your function to run, right? This is what you might see when running prun from the command line.įor me, since I will be calling this function many, many times, I want to try and eliminate whatever is taking the most time. There are also some options that you can insert as follows, when 'o' is the identifier of your option: When functionname is the function you want to test. You call is by simply writing, either on your command line on in a developing environment: Prun is a function that is part of the ‘core.magic’ module (so, no need to import anything! It’s super easy!). Tim (a graduate student in Professor Johnson’s group) showed me a couple cool tricks earlier this summer in making code more efficient, all of which I have been using ever since! I will show here my personal favorite diagnostic tool, prun. I don’t want to be a comedian, though: I want to be a competent coder! Well, I did realize in Ay117 (the astrostats course I took this past spring) that my five-deep for loops could cause laughter when shown to others. I started out knowing very little about making code efficient. This summer, this has begun to haunt me I need to run little chunks of code thousands of times as I approach my correct parameters in a Markov Chain Monte Carlo (this process I am also trying to make more efficient, but, more on that later). It might run and get the job done, but when you look at the actual raw code you will see recursive for loops and a stark lack of commenting, variable names like ‘bunny’ and ‘widget’ (hey, it seemed cute at the time! Who knew I would need to come back to this code later?) and almost every other mark of a rookie you can think of. So, no formal training), I am what I term a ‘functional coder.’ I can write code. Having never had formal training in coding (barring a high school course, in which we spent several months on ‘Hello World’…. Since it’s been a while, I think I will write about how to make your python code more efficient! (Also, writing this up means I can stop being stuck on my project for a few minutes… hence, thus I posit my ulterior motive…)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |