Best way to measure the performance of my code

Página 1/2
| 2

Por albs_br

Champion (499)

imagem de albs_br

25-07-2020, 00:52

I'm on the final stages of my game development and doing some optimizations on code, but is not very easy to see some small improvements in the characters speed on screen, so I ask you guys: is there a less amateur way to do this?

I'm thinking some emulator should have a feature to measure the number of times a certain point of code is reached, so I would put it on my main loop.

Entrar ou registrar-se para comentar

Por Grauw

Ascended (10822)

imagem de Grauw

25-07-2020, 02:04

The traditional way is to change the background colour at certain spots in your code and see how many lines it covers. Each line is 228 Z80 cycles, it works quite well for vsynced code, but even for non-vsynced code you can pause the emulator and count the number of lines. Some lines are hidden in the border and sync, so those spots can be difficult to measure.

But nowadays I use a performance profiling TCL script that I made for openMSX, which I shared in this thread. It reports cycle accurate measurements. A thousand times better :).

Por albs_br

Champion (499)

imagem de albs_br

25-07-2020, 02:37

It looks like the emulicious emulator has a profiler too, but I still don't understood how it works.

Por Calindro

Rookie (18)

imagem de Calindro

25-07-2020, 03:20

Which profiler are you trying to use? The general purpose one or the procedure profiler?
The general purpose profiler is meant to profile specified blocks of code and the procedure profiler is meant to profile procedures of your code. Also note that the procedure profiler has 2 views: Call Tree view and Hot Spots view.

Also feel free to contact me using the contact form on https://emulicious.net/contact/ :)

Por albs_br

Champion (499)

imagem de albs_br

25-07-2020, 04:48

I think asking here is better because can help other persons with same issue.

I want to know how many times / second my main loop runs:

MainLoop:

    call ReadInput

    call UpdateScreen

    call GameLogic

    ; call Delay

    call IncrementCounter

    jp MainLoop

Por salutte

Master (165)

imagem de salutte

25-07-2020, 06:37

I was also working on a TCL profiler that gives this kind of information, but I had not time to work on it as of lately. Maybe I can re-take it after the MSX-DEV.

Por Metalion

Paragon (1629)

imagem de Metalion

25-07-2020, 10:28

In Blue MSX (but I guess other emulators as well), you can easily measure the number of Z80 cycles it takes to execute your code. Just put a breakpoint before and a breakpoint after it. In the debugger, you can see the Z80 clock counter in CLH and CLL (32 bits number). Take note of the value before and after. Substract them, and voilà !

Por Calindro

Rookie (18)

imagem de Calindro

25-07-2020, 11:45

Alright, for that the general purpose profiler is perfectly suited.
In the Profiler window select the "General" tab then for both, Start and End enter "MainLoop".
(That tells the profiler to make its meassurements from the address MainLoop to the address MainLoop. So each meassurement corresponds to an execution of your loop.)
Then in the Cycles column you can see how many cycles your loop takes at minimum / at maximum / on average.
In the scanlines column you can see how many scanlines have passed min/max/avg.
When you hover the Cycles column it converts the cycle numbers to milliseconds.
That's not directly how many times per second but you can easily calculate that from these values.
For example when you have around 16ms that's around 60 times per second, with around 20ms you have 50 times per second and so on. Smile

Por Calindro

Rookie (18)

imagem de Calindro

25-07-2020, 14:10

Sorry for double post but I don't seem to be able to edit my post anymore. I thought I should probably elaborate on how ~16ms relates to ~60 times per second and ~20ms relates to ~50 times per second: The Cycles column of the general purpose profiler shows the cycles (and ms on hover) spent by one execution of your loop. So for example if it shows 20ms that means the loop took 20ms of emulated time. In order to calculate the number of times the loop was executed per second you need to divide 1000ms (1 second) by the time spent by a single execution. So in the example with 20ms that means you need to calculate 1000ms/20ms = 50. Or 1000ms/16.7ms = ~60.

Por inchl

Expert (105)

imagem de inchl

25-07-2020, 16:23

-

Por inchl

Expert (105)

imagem de inchl

25-07-2020, 16:23

Grauw wrote:

The traditional way is to change the background colour at certain spots in your code and see how many lines it covers. Each line is 228 Z80 cycles, it works quite well for vsynced code, but even for non-vsynced code you can pause the emulator and count the number of lines. Some lines are hidden in the border and sync, so those spots can be difficult to measure.

But nowadays I use a performance profiling TCL script that I made for openMSX, which I shared in this thread. It reports cycle accurate measurements. A thousand times better :).

Interesting... would it also be possible to measure the time the vdp is in CE-ready mode? The less the better!

Página 1/2
| 2