Go single threaded vs multi threaded (performance)

1,625 views
Skip to first unread message

Max

unread,
Jun 28, 2012, 12:49:48 PM6/28/12
to golan...@googlegroups.com
Does Go work faster in single thread mode?

I mean that in multi thread mode Go must call OS for synchronization.
But in single threaded mode Go may use only some volatile boolean variable to implement lock.

Also in single threaded mode memory management may be faster.

Christoffer Hallas

unread,
Jun 28, 2012, 12:53:07 PM6/28/12
to Max, golan...@googlegroups.com
Depends on what you're doing, obviously :)

Brad Fitzpatrick

unread,
Jun 28, 2012, 1:02:42 PM6/28/12
to Max, golan...@googlegroups.com
Yes, in many cases.  There's ongoing planning to fix this, though.

For now, just benchmark your code with GOMAXPROCS=1 vs GOMAXPROCS=n where n is >1.

Max

unread,
Jun 28, 2012, 1:27:19 PM6/28/12
to golan...@googlegroups.com, Max
It was great idea to make a bench )))

Single threaded app is 10 times faster then 2 threaded app.


In playground you can't see results. Timer is not working

On my windows laptop it is 
2 threads 2.5 seconds
1 thread 0.25 seconds

Not sure if it makes much sense in real world but I was expecting something like that.

Will continue benching

Rob 'Commander' Pike

unread,
Jun 28, 2012, 1:45:05 PM6/28/12
to Max, golan...@googlegroups.com
If your program isn't parallel, there's no reason to use multiple processors.

-rob
Message has been deleted

Max

unread,
Jun 28, 2012, 2:05:50 PM6/28/12
to golan...@googlegroups.com, Max

If your program isn't parallel, there's no reason to use multiple processors.

If I add second CPU then I wish app to work 2  times faster but often app works as fast as it works on 1 CPU
But that example shows that if I activate second CPU(thread) then app works 10 times slower.
It is good and expected results. It means that Go is clever enough to not make OS calls for synchronization in single threaded mode

My laptop is intel i3 4 cores
Reply all
Reply to author
Forward
0 new messages