简体   繁体   中英

Number of cycles taken for C++ or ANSI C?

Is there anywhere on the web where i can get an idea of what the various programming language syntax take in terms of processor (Core i7 and Core 2) cycles? At university i learnt the ARM assembly language and we could map the number of cycles taken to do a subtraction operator etc. I just wondered if its possible to do this with a higher level language on the Core i7 or Core 2?

No. That's completely dependent on the compiler you use, and what optimization settings you use, etc.

You can use your favorite compiler and settings to generate assembly code, and from the assembly code you can make these kinds of predictions.

However, remember that on modern architectures things like memory latency and register renaming have large effects on speed, and these effects are not obvious even from inspection of the assembly code.

In general, in higher-level languages, individual statements don't map cleanly onto specific sequences of machine-code instructions. The compiler will typically optimise things, which will involve various transformations, arrangements, and even eliminations, of instructions. Therefore, it's not usually meaningful to quote metrics like "a for expression takes 20 cycles".

You have to map higher level instructions into assembly instructions manually, or look at the assembly listing. And then look here

http://gmplib.org/~tege/x86-timing.pdf

or here

http://www.intel.com/Assets/PDF/manual/248966.pdf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM