Counting cycles

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
unclouded
Posts: 81
Joined: 24 Feb 2015

Counting cycles

Post 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.
leepivonka
Posts: 168
Joined: 15 Apr 2016

Re: Counting cycles

Post 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.
User avatar
MichaelM
Posts: 761
Joined: 23 Apr 2012
Location: Huntsville, AL

Re: Counting cycles

Post by MichaelM »

The approach that I use for counting cycles is to use the py65 simulator. It has a cycle counter function built-in.
Michael A.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Counting cycles

Post by BigEd »

And there was me about to suggest visual6502...
User avatar
BB8
Posts: 57
Joined: 01 Nov 2020
Location: Tatooine

Re: Counting cycles

Post by BB8 »

Some emulators do that. Vice for example.
Attachments
ViceCycleCount.jpg
laubzega
Posts: 6
Joined: 07 Oct 2020

Re: Counting cycles

Post by laubzega »

sim65 from cc65 package will count cycles when started with -c or --cycles.
IamRob
Posts: 357
Joined: 26 Apr 2020

Re: Counting cycles

Post 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.
unclouded
Posts: 81
Joined: 24 Feb 2015

Re: Counting cycles

Post 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/?
Post Reply