# Is it true that copying is the most CPU intensive operation?

A mech engineer said that copying puts more load on the microprocessor than "other" operations (e.g. moving data or creating the same amount of new data). Is this true? Can you elaborate? I understand that the assembly instructions are different but not how copying is "more intensive" ?

With copying what is meant is probably something like memcpy in C and with moving what is meant is probably the MIPS instruction mov between registers or between primary memory.

• What distinction do you have in mind when you distinguish between "copying" and "moving" data? They sound like the same thing to me. – The Photon Jul 21 '13 at 17:14
• @ThePhoton I tried to update the question to reflect the answer to your comment. Thanks. – Niklas R. Jul 21 '13 at 18:14

A basic microprocessor works at a fixed speed at assembly level. For the most part it can execute "instructions" in a certain number of clock cycles and that is that. The clock is usually fixed in speed (i.e. 8MHz for example) and an instruction might take 4 clocks cycles for example. This mean it executes an instruction (in this arbitrary example) in 500nsecs.

If you programme a micro to do more complex stuff, you are usually asking it to execute a sequence of several "instructions" and this naturally takes longer - it doesn't put more load on anything (like a mechanical engineer might envisage putting load on a shaft or a beam) - it just takes more time to do more complex things.

"Copying" might mean "read a value in memory and store it in another area of memory". To do this usually involves 2 instructions; one to read the value stored in memory and a second instruction to store it in another area of memory. It can be a little more complex than this of course - you need to setup the target address in memory and you need to setup the destination address - doing this might involve a couple more instructions but does the load on the micro change? Not really because in a simple micro it would be doing something like looping and waiting for an input to change so it can process some more data.

No.

A CPU is a complex system, build from sub-systems, and there is probably no load which will stress all the sub-systems heavily and thus no load which merit the name "most CPU intensive operation", whatever you come up, you can probably find a sub-system which can be used more with another load.

Doing memory copy will stress one sub-system -- the memory interface -- and that's all. It won't stress anything else, and it's perhaps even not the most meaningful load for the memory subsystem (writing as much data as it is read is usually just one operation that is tested by memory bandwidth benchmarks).

The answer is very dependent upon which kind of system you discussed.

In PCs, the following relations hold:

1. Moving the data is the simplest and the shortest procedure. Usually it involves just pointers changes, without actually modifying memory's contents.
2. Writing new data and copying usually takes the same order of magnitude of operations. CPU must allocate memory for the new data, program the DMA engine with the source and the destination addresses, program the DMA engine with additional parameters (amount of data to transfer, various flags, etc.) and after the DMA is launched, the CPU is no longer needed.

My intuition says that on every architecture the copying and the writing will take the same (actually comparable) CPU time (with and without DMAs). This comes from the fact that writing to memory is essentially copying from another location.

However, the above discussion concerned just the number of operations CPU performs. It may be the case that your friend meant runtime when he spoke about "load on microprocessor". Well, there is no point in discussing the runtime in presence of a DMA - it is not the CPU who performs the majority of the work. Without DMAs the moving is still the fastest (assuming that it is not the simplest microprocessor which executes move as a transfer of data), but the relation between copying and writing will depend on the source from which the write data is acquired: if this source has lower latency than the memory, the write operation will be faster; if the source have higher latency than the memory, the write operation will be slower.

In any case, it is difficult to say whether your friend is correct without getting the whole context of your discussion.

Regards