Page 1 of 1

Counting cycles

Posted: Thu Aug 05, 2021 12:26 am
by unclouded
What tools are available for counting cycles? I'm interested in comparing the performance of different implementations of a subroutine, but I don't want to count cycles by hand because I'm likely to make a mistake.

Re: Counting cycles

Posted: Thu Aug 05, 2021 12:57 am
by leepivonka
One option is to set up & run some test cases in a simulator that counts execution cycles.
For example: the Kowalski assembler & simulator: viewtopic.php?f=8&t=5011

A related option is to set up & run some test cases on real hardware with a timer.

Another option is to do static analysis on your subroutine. I assume this is what you were thinking of as complex & error-prone.
You would look up & sum the cycles required for each case of each instruction on the various execution paths through your subroutine.

Re: Counting cycles

Posted: Thu Aug 05, 2021 1:04 am
by MichaelM
The approach that I use for counting cycles is to use the py65 simulator. It has a cycle counter function built-in.

Re: Counting cycles

Posted: Thu Aug 05, 2021 7:25 am
by BigEd
And there was me about to suggest visual6502...

Re: Counting cycles

Posted: Thu Aug 05, 2021 12:04 pm
by BB8
Some emulators do that. Vice for example.

Re: Counting cycles

Posted: Fri Aug 06, 2021 3:52 am
by laubzega
sim65 from cc65 package will count cycles when started with -c or --cycles.

Re: Counting cycles

Posted: Fri Aug 06, 2021 11:41 pm
by IamRob
If the accuracy of cycle counting is not needed, then just call your subroutine then a speaker toggle switch, one after the other and in a loop, multiple times. The speaker will toggle faster for a fast subroutine and make a higher pitch.

Re: Counting cycles

Posted: Sun Aug 08, 2021 9:23 am
by unclouded
Thank you all for the suggestions. I love the speaker idea for comparing relative performance. I already had cc65 but didn't realize that sim65 was there. Is the sim65 in cc65 related at all to the sim65 at http://www.wsxyz.net/sim65/?