0

The following text is discussing the historical development of UNIX:

The next important milestone was the rewriting of UNIX in the programming language C. This was an unheard-of strategy at the time. It was generally felt that something as complex as an OS, which must deal with time-critical events, had to be written exclusively in assembly language. Reasons for this attitude include the following:

  • Processor and bus speeds were relatively slow, so saving clock cycles could make a substantial difference in execution time.

I don't understand why saving clock cycles would result in faster execution time.

Isn't it true that the faster (and more frequent) clock cycles are the better the execution time of the processor? In that case, wouldn't the goal be to increase clock cycles rather than "save" (reduce) them?

I would greatly appreciate it if someone could please take the time to clarify this point.

4
  • You're missunderstanding 'saving' them. You want to reduce the amount of clock cycles you need, for any particular task. – djsmiley2kStaysInside Jan 18 '17 at 15:12
  • @djsmiley2k Thanks for the response. That's my point: why would you want to save them when more cycles = faster? Or am I still misunderstanding something? – The Pointer Jan 18 '17 at 15:13
  • 2
    It means saving how many are used - If you imagine each clock cycle you can run 1 command. So you want your program to run in as few commands / cycles as possible. You only ever get the fixed number of cycles per second. – djsmiley2kStaysInside Jan 18 '17 at 15:23
  • "I don't understand why saving clock cycles would result in faster execution time." - Every instruction takes time to process, the more instructions you have, the longer whatever was calling those instructions takes to finish. *Basically a compiler can do a better job of optimizing then a human can.v – Ramhound Jan 18 '17 at 15:44
0

When you program in assembler (machine code) you know how many cpu cycles use each instruction, so you know in advance how much time will take a routine.

However, if you use a high level language that is compiled (a compilation is a translation to machine code) then it is more uncertain how much time a process can take. Besides of that there is a dependency of the ability of the compiler to optimize the final code according to the type of CPU used.

Non-optimized code means more CPU cycles to do the same task.

2
  • Point of clarification: When you compile C code, you are translating that into assembly, which is then processed as machine code. Assembly is a human interpretation of the machine code. You can still estimate the computation time when dealing with C or even languages like Java and C#. Machine code isn't always a 1:1 analog of assembly code. Assembly code vs Machine code vs Object code? – Ramhound Jan 18 '17 at 16:11
  • @Ramhound Yes. it's true. I over simplified it to make it more understandable. – jcbermu Jan 19 '17 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.