Simulator for code execution time?

Is it possible to simulate an Arduino sketch on the computer?

I want to check how long certain routines and functions take. So instead of the "millis and serial.print" approach, a debugger would be the first choice.

-Is the Atmel Studio with the Visual Micro Arduino plugin able to do that or is the additional USB debugger necessary for debugging?

A second -and preferred- choice would be an entire Arduino simulator so omitting the pain of uploading every slightly changed sketch to the microcontroller.

-I have found a few Arduino simulators, mainly "ArduinoSim", "Codeblocks Arduino IDE" and "Simuino", but I have no experience with either of those. Can someone give some pros & cons of the above or recommend a different program for measuring code execution time?

emulare is a simulator for the Arduino (actually, for the ATMega 328 used on the Arduino Uno). It should be clock cycle accurate. However, it is slower than an Arduino (8 to 16 times slower on my laptop) so the "millis and serial.print" approach may actually save you time. emulare has a problem with interrupts, so things like SoftSerial are problematic.

Even a simulator has to have "the pain of uploading every slightly changed sketch to the microcontroller" so I am not sure what you are really accomplishing here.

emulare allows you to wire up your microcontroller into a circuit, and even will simulate multiple microcontrollers.

I have used emulare with things like Serial.println(millis())) to get timing information. It is handy when you need to simulate microcontrollers that you don't actually have on hand, but it takes longer than just using an Arduino.

Good Luck!

This is not what you are looking for but it may be of interest:

Simulators aren't going to time how long the chip really takes, are they? I suggest either using the class mentioned in the previous reply, or toggle an LED at the start and end of the functions are you interested in, and measure the distance between toggles with a logic analyzer.

Thank you so far for the feedback!

@vaj4088
Sounds interesting, I will look into that emulator.

@Nick Gammon
I like the logic analyzer approach!

Ok, so the (precise) measuring of times aside, but staying with an emulator / software:
(How) is it possible to watch a variable over time, i.e. debugging code without having it running on a physical microcontroller?

I can't imagine why you would need to know precise timing unless it was for a very specific situation and in that case I would think the only practical way to get useful information would be measurement of the actual code on the actual device.

Repeating code in a loop 1000 or 10,000 times and recording the time (millis() or micros() ) before and after the loop is a simple way to time some things, or to compare different options.

...R

Try Simulator for Arduino here http://www.virtronics.com.au With timing, we ultimate roughly 1 microsecond per sketch instruction which should be close. To get accurate timing, it would be necessary to get down to the AVR core level. The millis value is always displayed on the main window accurate to 0.001ms.