2

I'd like to profile some basic Python scripts to see how they vary in the number of bytecode instructions executed. I've been playing around with dis but haven't discovered how to do this.

I'm not talking about the amount of bytecode for a certain .py file -- I'm talking about the number of bytecode instructions executed in a particular runthrough.

The bigger picture is that I'd like to have a measure of the relative complexity of various scripts as you work out the code by hand---but for very simple intro to programming problems.

Thanks for any help!

nova
  • 205
  • 1
  • 9
  • Well, I wouldn't do that, because some bytecodes take a lot more time than others, such as anything that does memory allocation, or anything that calls a vector or matrix operation (not to mention disk or console I/O). If you are trying to find out how to get maximum performance, you should know how to use [*this technique*](http://stackoverflow.com/a/4299378/23771). – Mike Dunlavey Apr 13 '17 at 00:36
  • I'm not really interested in how fast it takes for a computer though. I'm thinking of testing whether number of bytecode executions might correlate with how long it takes a beginner programmer to trace through the problem. Just a random idea I thought might be crazy and fun. – nova Apr 14 '17 at 20:54
  • 1
    OK, that's interesting. (You might say it in the post.) I taught intro CS (30+ years ago), which is a process of, one by one, putting tools into students' heads so they can think about and create programs. One of the tools is "play computer", where you personally step through the program to see what it does. That helps to fix misconceptions they have, like thinking that, since the program is so fast, it must do everything all at once. Another misconception is they think it reads their mind. Your problem sounds like fun. – Mike Dunlavey Apr 16 '17 at 13:40
  • We are on the same page with "play computer"! I think that's crucial to address misconceptions like the one you mention. If I pursue this further, I'll update this post with my technique(s). – nova Apr 20 '17 at 17:34

0 Answers0