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: 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....
 
2022-02-28 21:50
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.
2022-03-01 23:21
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).
2022-03-02 04:04
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.
2022-03-02 09:50
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.
2022-03-02 10:04
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. :)
2022-03-02 13:04
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 :)
2022-03-02 15:06
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
2022-03-03 11:50
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/
2022-03-04 07:47
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"
2022-03-08 14:36
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
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
Rhythm/G★P
Mibri/ATL^MSL^PRX
Tommy/Noice^DCS
The Syndrom/TIA/Pret..
encore
Smasher/F4CG
radius75
Guests online: 82
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.6)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Sprite Bukkake 2  (9.6)
9 Uncensored  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 X-Mas Demo 2024  (9.6)
6 Xmas 2023 Silent Night  (9.5)
7 Katzen-Video.mp4  (9.5)
8 Selbuvotter Latitudes  (9.5)
9 Xmas 2024  (9.5)
10 Rainbow Connection  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Performers  (9.3)
4 Fairlight  (9.3)
5 Triad  (9.3)
Top Coders
1 Axis  (9.8)
2 Sailor  (9.8)
3 Graham  (9.8)
4 Lft  (9.8)
5 Crossbow  (9.8)

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