Questions tagged [cpu-cycles]
90 questions
4
votes
5 answers
Measuring CPU clocks consumed by a process
I have written a program in C. Its a program created as result of a research. I want to compute exact CPU cycles which program consumes. Exact number of cycles.
Any idea how can I find that?

hasanatkazmi
- 8,041
- 2
- 22
- 18
4
votes
3 answers
which operation takes more CPU clocks, modulo or comparison?
Which operation takes more CPU clocks, modulo or comparison?
Will this code take more time:
for(j = i; j <= 10; j++)
{
if(j == 10) printf("0");
else printf("%d", j);
}
or this
for(j = i; j <= 10; j++)
printf("%d", j % 10);
and why?

mannuscript
- 4,711
- 6
- 26
- 25
3
votes
1 answer
What is the fast modulo replacement for random number generation?
Currently I'm using a very fast XorShift algorithm:
inline uint r() {
static uint y = 2463534242u; // seed
y ^= (y<<13);
y ^= (y>>17);
y ^= (y<<5);
return y;
}
Now I want to generate an integer from interval [0, n). Of course I can do…

Łukasz Lew
- 48,526
- 41
- 139
- 208
3
votes
1 answer
Counting CPU cycles with `perf_event` in C yields different value than `perf`
I try to count the CPU cycles of a single process via a short C code snippet. A MWE is the cpucycles.c.
cpucycles.c (heavily based on the man page example)
#include
#include
#include
#include
#include…

Chickenmarkus
- 1,131
- 11
- 25
3
votes
3 answers
CPU cycles in Arduino uno for Digital read and counting pulses
I'm trying to count number of HB100 microwave sensor pulses in 200ms time quanta.
Here is the code:
#include
#include
elapsedMillis ElapsedTime;
#define Sensor A0
#define TimeQuanta 200
int Counter = 0;
boolean…

Mehran
- 307
- 1
- 3
- 15
3
votes
1 answer
Why do memory instructions take 4 cycles in ARM assembly?
Memory instructions such as ldr, str or b take 4 cycles each in ARM assembly.
Is it because each memory location is 4 bytes long?

kyczawon
- 455
- 6
- 14
3
votes
1 answer
how many cpu cycle takes to execute MOV A, 5 instruction
My question is calculate how many CPU cycle takes to execute MOV A, 5 instruction. Describe each.
can anyone please explain me how this works. And the 5 is a value is it? Just explain me the main points.
As far as i know,
first,
-get the…

LekhAsh
- 31
- 2
3
votes
3 answers
Limiting assembly execution number of cpu cycles
I have a project that dynamically loads in unknown assemblies implementing a specified interface. I don't know the contents or purposes of the assembly, other than it implementing my interface.
I need to somehow restrict the amount of processing…

Mark S. Rasmussen
- 34,696
- 4
- 39
- 58
2
votes
1 answer
Measurement of CPU cycles with perf
Currently I'm working on measuring the time of code execution.
I can measure how much time took to execute function (using tracepoints) but I also need to measure how many cpu cycles the execution of funcB took, and it would be good to know how perf…

MateoFerenc
- 23
- 6
2
votes
1 answer
How to measure the ACTUAL number of clock cycles elapsed on modern x86?
On recent x86, RDTSC returns some pseudo-counter that measures time instead of clock cycles.
Given this, how do I measure actual clock cycles for the current thread/program?
Platform-wise, I prefer Windows, but a Linux answer works too.

user541686
- 205,094
- 128
- 528
- 886
2
votes
1 answer
Measure CPU clock cycles per operation in python
I'd like to know how'd you measure the amount of clock cycles per instruction say copy int from one place to another?
I know you can time it down to nano seconds but with today's cpu's that resolution is too low to get a correct reading for the…

Pongo
- 81
- 1
- 5
2
votes
2 answers
Unexpected timing in Arm assembly
I need a very precise timing, so I wrote some assembly code (for ARM M0+).
However, the timing is not what I expected when measuring on an oscilliscope.
#define LOOP_INSTRS_CNT 4 // subs: 1, cmp: 1, bne: 2 (when branching)
#define…

SupAl
- 517
- 3
- 12
2
votes
1 answer
clock_gettime takes longer to execute when program run from terminal
I was trying to measure the time for a snippet of code and noticed that the timings were about 50ns faster when I ran the program from inside my editor, QtCreator, compared to when I ran it from a bash shell started in a gnome-terminal. I'm using…

Daniel Näslund
- 2,300
- 3
- 22
- 27
2
votes
1 answer
Understanding STM8 pipelining
I’m trying to understand STM8 pipelining to be able to predict how much cycles my code will need.
I have this example, where I toggle a GPIO pin for 4 cycles each.
Iff loop is aligned at 4byte-boundary + 3, the pin stays active for 5 cycles (i.e.…

rumpel
- 7,870
- 2
- 38
- 39
2
votes
1 answer
Why ADD is 4 cycles on Z80?
I use this ALU block diagram as a learning material : http://www.righto.com/2013/09/the-z-80-has-4-bit-alu-heres-how-it.html
I am not familiar with electronics. I am currently believing that a clock cycle is needed to move data from registers or…

Demeter Purjon
- 373
- 1
- 12