Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Count raw cycles of an execution (ignore VIC-stealed cycles) in VICE?
2022-02-28 17:25
wil

Registered: Jan 2019
Posts: 42
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....
 
2022-02-28 21:50
wil

Registered: Jan 2019
Posts: 42
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.
2022-03-01 23:21
JackAsser

Registered: Jun 2002
Posts: 1989
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).
2022-03-02 04:04
ChristopherJam

Registered: Aug 2004
Posts: 1378
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.
2022-03-02 09:50
Perplex

Registered: Feb 2009
Posts: 254
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.
2022-03-02 10:04
JackAsser

Registered: Jun 2002
Posts: 1989
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. :)
2022-03-02 13:04
chatGPZ

Registered: Dec 2001
Posts: 11113
Or perhaps even do everyone a favour and make a patch for VICE that will optionally ignore counting the cycles when BA is active :)
2022-03-02 15:06
Stone

Registered: Oct 2006
Posts: 168
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
2022-03-03 11:50
Skate

Registered: Jul 2003
Posts: 490
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/
2022-03-04 07:47
oziphantom

Registered: Oct 2014
Posts: 478
you can run the function with this https://github.com/martinpiper/BDD6502 and it will tell you how many cycles the "test ran for"
2022-03-08 14:36
Martin Piper

Registered: Nov 2007
Posts: 634
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
chesser/Nigaz
Didi/Laxity
Mike
Gordian
Genius/Xenon
zscs
Grue/Extend
Guests online: 124
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Logo Graphicians
1 Sander  (10)
2 Facet  (9.7)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.043 sec.