# Why 4 threads run faster than 2 on my dual core?

**URL:** <https://forum.kirupa.com/t/why-4-threads-run-faster-than-2-on-my-dual-core/283663>\
**Category:** programming\
**Created:** [March 9, 2009, 8:15pm UTC](https://forum.kirupa.com/t/why-4-threads-run-faster-than-2-on-my-dual-core/283663 "2009-03-09T20:15:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [March 9, 2009, 8:15pm UTC](https://forum.kirupa.com/t/why-4-threads-run-faster-than-2-on-my-dual-core/283663/1 "2009-03-09T20:15:56Z")

</div>

I’ve built a ray tracer in Java. It generates images like this:

![](http://www.lightandmatter.com/html_books/5op/ch01/figs/computer-ray-tracing.jpg)

(this is not mine, it’s just an example). I multithreaded it by cutting up the image horizontally and telling each thread to render a chunk of the final image. I did quite a few tests and these are the average times:

1 thread: 35 seconds  
2 threads: 21 seconds  
4 threads: 20 seconds  
8 threads: 21 seconds

I own a Intel Wolfdale @ 3.0 GHz (Dual Core). The improvement when going to 2 threads is obvious, but I can’t make sense of why going to 4 threads makes it go even faster. I thought Intel didn’t have hyperthreading since Pentium IV, so my 2 cores mean that I can only run 2 threads simultaneously. The dip in 8 threads makes sense because of more context switching.
