Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyper-threading Performance Comparison

I have written a project, which uses some basic functions in openssl such as RAND_bytes and des_ecb_encrypt.

My computer has i7-2600(4 cores and 8 logic CPU). When I run my project with 4 threads, it will costs 10 seconds. When I run it with 8 threads, it also costs 10 seconds.

What I mean is that hyper-threading doesn't give me any performance improvement. In Linux, the experiment result is same.

I found here tells me that hyper-threading doesn't give me some improvement in some situations. Also, I found here give me some intuitive results.

However, I have tried to write some simple tests and found some simple examples which will show hyper-threading won't give me apparent improvement. Sadly, I don't find it.

So, my questions is that whether there are some simple tests shows the hyper-threading won't give me any performance improvement.

like image 950
Yulong Tian Avatar asked Jan 17 '26 23:01

Yulong Tian


2 Answers

You may find that hyperthreading helps more on code that is using large amounts of memory, so that the processor is regularly blocked on fetching from memory.

In my experience, it's quite hard to find "simple code" that shows benefits from hyperthreading. It tends to be more complex examples that show the benefit. Still, the benefit will most likely not be 2x that of "no hyperthreading". Count on getting perhaps 20-30% improvement.

like image 178
Mats Petersson Avatar answered Jan 20 '26 14:01

Mats Petersson


Hyper threading takes advantage of the fact that the CPU has many components and when one is used, when there's no hyper threading, the others just sit there idle. You can try writing two types of threads, one doing integer calculations (that will hopefully use the ALU) and one doing floating point arithmetic (that will hopefully use the FPU).

I did not try this myself but it seems that in such a scenario hyper threading should improve the performance.

To show the opposite you can use only one type of the threads (either threads only doing integer operations or threads only doing floating point operations).

It may also be that your test is flawed, but in order to know if that is the case we'll need more information about that test.

like image 32
selalerer Avatar answered Jan 20 '26 16:01

selalerer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!