| |
wil
Registered: Jan 2019 Posts: 62 |
Count raw cycles of an execution (ignore VIC-stealed cycles) in VICE?
Is there an easy way to measure the execution time of an assembler program with VICE?
I know VICE has the CPU cycle counter and even a function for displaying/resetting the cycle counter (stopwatch, by the way, this can be abbreviated with sw, although this feature is not documented) but the cycle counter counts clock cycles also when the CPU is halted due to a VIC memory access.
However, I would like to measure the net used cycles instead of the clock cycles passed.
Currently, I am switching VIC off (0 -> $d011) and waiting for a new frame (and, of course, switch off IRQ) to do my measurements. But I wonder if there is a more elegant version, probably an executed clock cycle counter buried somewhere in VICE? |
|
... 2 posts hidden. Click here to view all posts.... |
| |
wil
Registered: Jan 2019 Posts: 62 |
Sure, switching off VIC-DMA is sufficient, it is just a bit laborious adding the blanking code to my program just because I want to measure a function - especially since VICE comes with this built-in stopwatch feature.
And this also has a history - I was optimizing some loops and was not aware that the stolen cycles were also counted in VICE. So I did a small change ... the number got better ... another change ... the number got worse. Until stupid me realized that the changes were mostly depending if there was a badline more or less during the measurement.
Of course I should have known... I have used the CPU cycle counter before for optimising horizontal raster positions. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Doing your own 6502 CPU emulation that counts cycles is a days worth of coding, tops. I did that several times to measure speed. Just do it (tm). |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
The other option is repurposing some other existing tool. I tap into Unp64 V2.35 for profiling while I'm doing cruncher dev, which is admittedly already set up for, but it's reasonably sane to tell it to "execute from {here} until it jumps to {there}"
It's fairly trivial addition to get it to also dump a file giving the total number of cycles spent executing instructions at each address, so you can then identify hotspots. |
| |
Perplex
Registered: Feb 2009 Posts: 255 |
If you don't fancy spending a day (or several days - not all of us are JackAssers) writing your own CPU emulator, you can instead spend an hour or two writing a script to parse the VICE trace to measure cycles spent and deduct cycles spent on DMA or interrupt handlers, both of which are clearly marked in the trace. |
| |
JackAsser
Registered: Jun 2002 Posts: 2014 |
Quote: If you don't fancy spending a day (or several days - not all of us are JackAssers) writing your own CPU emulator, you can instead spend an hour or two writing a script to parse the VICE trace to measure cycles spent and deduct cycles spent on DMA or interrupt handlers, both of which are clearly marked in the trace.
Well, we have certainly discussed the topic longer than it takes to write the code. You don't even need to do a full implementation, just the opcodes actually used by the code you wanna measure. :) |
| |
chatGPZ
Registered: Dec 2001 Posts: 11387 |
Or perhaps even do everyone a favour and make a patch for VICE that will optionally ignore counting the cycles when BA is active :) |
| |
Stone
Registered: Oct 2006 Posts: 172 |
I added cycle counting to Cadaver's cpu emulator in SIDDump a while back. It is only a .c and .h file and is easily integrated into your own tools.
SIDDump V1.08 |
| |
Skate
Registered: Jul 2003 Posts: 495 |
Modifying Vice is the best option. Many of us have our own 65xx cpu emulators, disassemblers etc. But if you don't want to spend much time on preparing the required compiler and tool chain etc, quick solution would be to modify a JavaScript based 6502 emulator like the one below. If your routines are not C64 hardware dependent, it would probably take an hour or two to convert this to a cycle counter.
http://www.6502asm.com/ |
| |
oziphantom
Registered: Oct 2014 Posts: 490 |
you can run the function with this https://github.com/martinpiper/BDD6502 and it will tell you how many cycles the "test ran for" |
| |
Martin Piper
Registered: Nov 2007 Posts: 726 |
Adding on to what Ozi wrote. BDD6502 was expanded a little while ago to allow code to be executed and cycle counts to be checked automatically.
For example this example test: https://github.com/martinpiper/BDD6502/blob/master/features/Per..
This allows 6502 code to be checked for expected performance over a range of inputs/memory states. Most useful for performance testing to make sure code tweaks are still within budget while maintaining correct functionality.
I use it extensively for checking code as part of an automated build before even getting to run it in Vice and test manually. |
Previous - 1 | 2 - Next |