Wednesday, May 15, 2013

Parallel integer summation challenge Erlang vs CLR/C#

Today we have done an interesting benchmark in C# and Erlang. Basically the point was to compare the brevity and performance of two inherently different langs/approaches:

Erlang r16b:

$ cat t.erl

-module(t).
-export([t/0, t/1, ct/1, ct/2]).

-define(DEF_CNT, 10000000).

t() ->
    t(?DEF_CNT).
t(N) when is_integer(N) ->
    time_it(fun() -> test(N) end, N).

ct(Threads) ->
    ct(?DEF_CNT, Threads).
ct(N, Threads) when is_integer(N), is_integer(Threads) ->
    time_it(fun() -> ctest(N, Threads) end, N * Threads).

time_it(Fun, Divisor) ->
    {T, Result} = timer:tc(Fun),
    {T / (Divisor/1000000) / 1000, Result}.

ctest(N, M) ->
    Pids = spawner(self(), N, M),
    lists:foldl(fun(Pid, S) ->
        receive {Pid, Sum} -> S+Sum end
    end, 0, Pids).

spawner(_, _, 0) ->
    [];
spawner(Owner, N, M) ->
    [spawn(fun() -> loop(Owner, N) end) | spawner(Owner, N, M-1)].

loop(Pid, N) ->
    Sum = test(N),
    Pid ! {self(), Sum}.

test(N) -> test(N, 0).

test(0, M) -> M;
test(N, M) -> test(N-1, M+1).


C#, NET 4:

private void button4_Click(object sender, EventArgs e)
{
    const int CNT = 100000000;
    const int SPLIT = 1000000;

    var tasks = new Task[CNT / SPLIT];
       
         

    var w = Stopwatch.StartNew();
          
    for(int i=0,start=0; i    {
    tasks[i] = new Task( () =>
                                {
                                    long lsum = 0;
                                    long end = start + SPLIT;
                                    for(int c=start; c                                    return lsum;
                                }
                            );
    tasks[i].Start();
    }

    long sum = tasks.Sum( t => t.Result);
         
    w.Stop();

    var rate = CNT / (w.Elapsed.TotalSeconds);

    Text = string.Format("Total: {0} in {1} ms  at {2}/sec  {3} msec/million ",

  CNT,
 w.Elapsed.TotalMilliseconds, 
rate,
w.Elapsed.TotalMilliseconds / (CNT / 1000000)
);

    var s = sum;
    Text+= s.ToString();
}



Test results are really interesting:
  .NET      0.22 msec per million
  Erlang does this is 1.5 msec per million

CLR is 6.8 faster for this test.

Some other facts.  Linear loop single threaded that sums integers (not optimized out of code, I confirmed in disassembler)

PHP code:
 $CNT = 10000000;
 $sum = 0;
 $w = microtime(true);
 for($i=0; $i<$CNT; $i++) $sum += 1;
 $w = round((microtime(true)-$w)*1000,0);
 echo($w);


PHP standard runtime:  1040 ms
C#:                                     2ms

CLR is 500 times faster that PHP for this simple test




57 comments:

Anonymous said...

whats funny is that Task class really nullifies Erlangs huge benefit of green processes adventage over "heavy" langs like c#

Anonymous said...

Dima, I know that PHP sucks but what other choice now when 90% of my code is in it

oakleyses said...

nike air max, air max pas cher, p90x3, converse, ugg boots, ferragamo shoes, giuseppe zanotti, louboutin, moncler, mcm handbags, air max pas cher, ralph lauren, ugg outlet, soccer jerseys, valentino shoes, herve leger, babyliss pro, moncler, moncler, jimmy choo, vans, asics gel, air max, moncler outlet, chi flat iron, canada goose outlet, uggs on sale, hollister, canada goose, instyler ionic styler, moncler, canada goose, insanity, marc jacobs, tn pas cher, ray ban, canada goose outlet, air max, soccer shoes, canada goose, bottega veneta, ghd, ugg, celine handbags, ugg, gucci, canada goose, ugg boots, oakley

dody Love said...

شركة الصفرات لعزل الاسطح بالرياض
شركة الصفرات لعزل الخزانات بالرياض
شركة الصفرات لتنظيف الفلل بالرياض
شركة الصفرات لتنظيف المنازل بالرياض
شركة الصفرات لرش المبيدات بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لكشف تسربات المياه بالرياض
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الشقق بالرياض
شركة الصفرات لنقل عفش بالرياض
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لخدمات التنظيف

dody Love said...

شركة تسليك المجارى بالرياض
شركة شفط البيارات بالرياض
شركة تنظيف الخزانات بالرياض
شركة عزل الاسطح بالرياض
شركة تنظيف الشقق بالرياض
شركة تنظيف الفلل بالرياض
شركة رش المبيدات بالرياض
شركة مكافحة النمل الابيض بالرياض
شركة غسيل السجاد بالرياض
شركة كشف تسربات المياه بالرياض
شركة نقل الاثاث بالرياض
شركة رش مبيدات بأبها

dody Love said...

شركة تنظيف بجده
شركة تنظيف شقق بجده
شركة تنظيف فلل بجده
شركة تنظيف قصور بجده
شركة تنظيف خزانات بجده
شركة عزل اسطح بجده
شركة عزل خزانات بجده
شركة تنظيف مجالس لجده
شركة تنظيف مساجد بجده
شركة مكافحة النمل الابيض بجده
شركة رش مبيدات بجده
مكافحة صراصير المطبخ
شركة نقل اثاث بجده
شركة نقل عفش بجده
شركة مكافحةالنمل الابيض بأبها

Unknown said...

ugg boots
air jordan 13
air jordan shoes
beats headphones
bottega veneta outlet
burberry outlet
canada goose outlet
chanel outlet
cheap wedding dresses
coach outlet
dansko outlet
evening dresses
hermes belt
hermes birkin
hermes outlet
juicy couture outlet
kate spade outlet
mbt shoes
michael kors outlet
mizuno running
moncler coats
mulberry outlet
soccer shoes
nike outlet store
the north face outlet
oakley sunglasses
ray ban sunglasses
stuart weitzman boots
surpa sneakers
north face outlet
the north face clearance
the north face jackets
the north face outlet store
north face jackets
the north face uk
tommy hilfiger outlet
tory burch outlet
true religion jeans
vans shoes
ysl outlet

Unknown said...

20150623meiqing
louis vuitton
louis vuitton
fitflop footwear
oakley store
kate spade outlet
ralph lauren outlet
ray ban sunglasses
jordan 8 playoffs
oakley vault
toms outlet
www.louisvuitton.com
hollister
jordan concord 11s
michael kors outlet online
chanel bags
christian louboutin outlet
coach outlet
fitflops clearance
louboutin
louis vuitton outlet
coach outlet
coach outlet store online
marc jacobs handbags
toms promo code
oakley sunglasses wholesale
lebron james basketball shoes
prada
jeremy scott shoes
oakley sunglasses
abercrombie outlet
louis vuitton
discount oakley sunglasses
christian louboutin outlet
michael kors uk
ray ban wayfarer
concords 11
kd shoes
kate spade handbags
pandora charms
abercrombie & fitch

oakleyses said...

kate spade outlet online, nike air max, tory burch outlet online, ugg boots clearance, prada handbags, nike air max, ray ban sunglasses, michael kors handbags, chanel handbags, jordan shoes, nike outlet, longchamp outlet online, gucci handbags, christian louboutin, christian louboutin shoes, burberry outlet online, ugg outlet, oakley sunglasses, louis vuitton outlet, ray ban outlet, nike free, cheap oakley sunglasses, cheap ugg boots outlet, louis vuitton, longchamp outlet, michael kors outlet online, polo ralph lauren outlet, burberry outlet online, christian louboutin outlet, michael kors outlet online, oakley sunglasses, ray ban sunglasses, oakley vault, ugg australia, cheap ugg boots, red bottom shoes, replica watches, michael kors outlet, tiffany and co, tiffany jewelry, louis vuitton outlet online, replica watches, polo ralph lauren, prada outlet, louis vuitton handbags

oakleyses said...

pandora jewelry, swarovski uk, canada goose, moncler outlet, links of london uk, coach outlet, ugg boots, hollister canada, sac lancel, marc jacobs handbags, air max, pandora jewelry, converse, replica watches, vans, wedding dress, uggs outlet, canada goose pas cher, canada goose, uggs canada, louis vuitton uk, moncler, barbour, gucci, supra shoes, moncler outlet, canada goose, canada goose outlet, doke gabbana outlet, moncler, juicy couture outlet, sac louis vuitton, canada goose, canada goose outlet, montre femme, thomas sabo uk, ugg soldes, louis vuitton, louis vuitton pas cher, moncler, swarovski jewelry, michael kors outlet online, louis vuitton canada, barbour jackets, converse shoes, ugg, canada goose outlet, ugg, ray ban, karen millen, moncler

mmjiaxin said...

marc jacobs
nike foamposite
vans shoes
calvin klein outlet
ralph lauren outlet
michael kors outlet online
swarovski crystal
ferragamo outlet
cheap nike shoes
michael kors handbags sale
oakley,occhiali oakley,oakley italia,oakley occhiali,oakley sunglasses
moncler outlet store
the north face outlet
michael kors factory online
ralph lauren uk
nike air max
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
longchamp outlet
michael kors wallet sale
michael kors outlet
mm1202

Unknown said...




شركة الصفا والمروه لخدمات التنظيف
شركة تنظيف بالدمام
شركة تسليك مجاري بالدمام
شركة مكافحة حشرات بالدمام
شركة تنظيف شقق بالدمام
شركة تنظيف فلل بالدمام
شركة تسليك مجاري بالدمام
شركة تنظيف بالخبر
شركة كشف تسربات المياة بالدمام
شركة مكافحة النمل الابيض بالخبر

شركة تسليك مجاري بالجبيل
شركة تسليك مجاري بالخبر
شركة تسليك مجاري بالاحساء
شركة تسليك مجاري بالقطيف
شركة تسليك مجاري بالرياض
شركة تسليك مجاري بجدة
شركة تسليك مجاري بالباحة
شركة تسليك مجاري بتبوك

شركة كشف تسربات المياة بالاحساء
شركة كشف تسربات المياة بالقطيف
شركة كشف تسربات المياة بالجبيل
شركة كشف تسربات المياة بالدمام
شركة تسليك مجاري بالجبيل
شركة كشف تسربات المياة بالخبر

happy wheels games said...

I just want to say : why you do not click to play
puzzle games | mario games | brain games | tetris | happy wheels | agario | super mario | abcya

hosam gamal said...


شركة الروناء
شركة تسليك مجارى بابها
شركة تنظيف بابها
شركة تنظيف منازل بابها شركة رش مبيدات بابها
شركة مكافحة حشرات بابها
شركة نقل اثاث بابها
شركة تنظيف شقق بابها
شركة تنظيف خزانات بابها
شركة نظافة عامة بابها
شركة تسليك مجارى بخميس مشيط
شركة تنظيف خزانات بخميس مشيط
شركة تنظيف بخميس مشيط
شركة رش مبيدات بخميس مشيط
شركة كشف تسريبات بخميس مشيط

hosam gamal said...


شركة تنظيف شقق بخميس مشيط
شركة تنظيف منازل بخميس مشيط
شركة نقل اثاث بخميس مشيط
شركة نظافة عامة بخميس مشيط
مدرس قدرات بغرب الرياض

شركة تنظيف بجازان
شركة تنظيف شقق بجازان
شركة تنظيف منازل بجازان
شركة رش مبيدات بجازان
شركة مكافحة حشرات بجازان
نقل اثاث بجازان
شركة تنظيف بنجران


Ann Lily said...

I love reading your articles and I shared it with my friends.
People also like it and give good feedback. Thank you.
Signature: open facebook | facebook login | happy wheels | happy wheels game | earn to die | earn to die game

Unknown said...

Strike Force Heroes 1
For moving in the game you must use the keys Strike Force Heroes 1 or the arrows keys. If you want to jump you can use the keys Up, Space or W. For switching weapon you can use Q or Shift.
Strike Force Heroes 2
is here, much fun. In the second installment of the action-packed shooting game you have to take over your enemy space base at all costs. Move and shoot through several missions and don’t forget to kill all baddies.
Strike Force Heroes 3
It is always going to be a challenge if you are a member of the Strike Force. You will be sent out on challenging missions and that is exactly the situation here. You must eliminate all the enemies using the weapons available to you.

Ann Lily said...

Thanks for giving me the useful information. I think I need it!
See more at: happy wheels | happy wheels game | open facebook | happywheels | happywheels game
I would like more information about this, because it is very nice. Thanks for sharing!

Unknown said...

age of waraz game free
Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
game tanlk trouble
earn to die 3
game tank trouble
age of waraz23456

Unknown said...

our website is a professional , dashing and efficient way to communicate with your customers and Professional SMS Marketing are using the Bloomtools SMS Marketing tool will save your

Unknown said...



شركة تنظيف منازل بالاحساء
شركة تنظيف بالجبيل
شركة تنظيف خزانات بالاحساء
شركة تنظيف مسابح بالاحساء
شركة تنظيف مسابح بالجبيل
شركة تنظيق بالاحساء

Anonymous said...

Thank you so much for commenting, it is lovely and really makes my day!
wheely 8 games | zoxy 3 | twizlgames | papalouie 4

Anonymous said...

To be honest, when we started the project I wasn’t sure we could pull this off but you certainly did it and did it well.

GGG | moto x3m 3 | limaxio | gold miner game | happy wheels games

Yepi Games said...

You are such a team player.
Friv

Yepi

Troll Face

Friv1000

Anonymous said...

Troll Face Quest Video Games. Play. Troll Face Quest Video Games · Y10 City Heroes. the best free online Twizl games, juegos Twizl, jogos Twizlfrom the top game developers all over the world. Zoxy is the best entertainment site with free games.

Newbie said...

Best of friv 4 Games game series are waiting for you! Kizi 100 Games is a great place to play free online juegos kizi game, sport, girl, including puzzle, boy and more juegos de kizi 100 game! Enjoy and play Kizi!

Unknown said...

I liked it so much and very interesting, too! Thanks for sharing the experience.
Wonderful post, really great tips and advice.
friv 3
friv 4
kizi 2

Unblocked Games 66 said...

Easy smile who is also easy to cry. And at least they'll crushing silence.
Xbox One | Unblocked Games | Friv 2 | Unblocked | Yepi 2 | Titanfall 1

قمم التميز said...

شركة مكافحة الحشرات بالخرج
شركة مكافحة حشرات بالخرج
شركة مكافحة النمل الابيض بالخرج
مكافحة النمل الابيض بالخرج
شركة رش مبيدات بالخرج
شركة رش دفان بالخرج

Unknown said...

jaguars jersey
cheap jerseys
oakley sunglasses wholesale
ray ban sunglasses
ugg boots
replica watches
seahawks jersey
ralph lauren outlet
michael kors handbags
ralph lauren

alicetaylor said...

Thanks for sharing this quality information with us. I really enjoyed reading.

lennyfacetext.com

Unknown said...

I like to get up early to go out and breathe fresh air. I feel that it is good for health and a good habit
19216811ll.com

Syifa Zahra said...

thanks obat epilepsi di apotik jenis kista ovarium yang berbahaya

Anonymous said...

if you have any problem on your printer, please visit our website here, because a lot of tutorials on learning about problems on the printer, let's go now. click here too. besides that you also get other interesting information about printer problem please visit our website. click here

KIMI HIME said...

Thanks for the helpful information. Because, I just found out there is a very extraordinary article like this, thanks

Obat Biang Keringat untuk Bayi
Obat untuk Infeksi Usus
Obat Kurap yang Paling Ampuh
Agen Resmi QnC Jelly Gamat di Kudus
Cara Mengobati Bronkitis
Cara Mengobati Sipilis

شركة شام said...


يسر شركة شام ان تقدم لعملائها في مدينة القطيف افضل الخدمات المنزليه واليوم سوف نقدم لكم خدمة مكافحة نمل ابيض بالدمام وقد حرصنا علي ان تكون الخدمه التي نقدمها خدمه متميزه خدمه متوفر فيها جميع عناصر الاحترافيه والخبره ، وتندرج هذه الخدمه تحت مسمى
شركة مكافحة نمل ابيض بالدمام
ومن عناصر التميز التي حرصنا علي توافرها في هذه الخدمه وجميع الخدمات التي نقدمها لعملائنا الكرام المصداقيه واحترام الاتفاقات والمواعيد والحرص والحرص علي الوصول بالخدمه المقدمه الي اعلي درجات الاتقان والجوده ، عزيزي العميل مع شركة شام انت دائما بأمان .

Admin said...

Thank you for your support who has read our article. I'm very happy if you can share our article below

Toko Obat Herbal
Cara Mengatasi Nyeri Sendi
Obat Penyakit Jantung
Cara menambah HB darah
Cara Mengobati Milia

Penyebab Sering Mimisan said...


This article is interesting and useful. Thank you for sharing. And let me share an article about health that God willing will be very useful. Thank you :)

Obat gatal Kudis/gudik
Walatra Gamat Emas Kapsul
Vitamin Untuk Kesehatan Anak
Cara Mengatasi Cacar Air
Cara Menghilangkan Kantung mata
Obat Telinga Berkerak dan Berair

Unknown said...

0728jejeLa méthode chaussures new balance homme prix consiste à joindre la formule Phylon avec la mousse new balance soldes asos lunaire. Le pommeau était fixé à air jordan 1 retro alpha sa poignée en bronze moulé avec new balance femme pas cher sarenza une noix qui avait un point important new balance mode de vie qui, s'il était utilisé avec une tous les air jordan force suffisante, pourrait fracturer le crâne d'un homme. asics gel lyte iii homme pas cher

JannethManalu said...

Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know

https://tikibet88.com
Agen Sbobet Termurah
Agen Sbobet Terpercaya
https://tikibet88.net
http://tikibet88.info
http://tikibet88.org

ركن كلين said...

Thank you very much for accepting the comment
شركة تنظيف فلل بالرياض
ارخص شركة تنظيف منازل بالرياض
شركة تنظيف وغسيل كنب بالرياض
شركة تنظيف السجاد بالرياض
شركة تنظيف ستائربالرياض
شركة تنظيف مكيفات بالرياض
شركة غسيل مكيفات بالرياض
افضل شركة تنظيف مكيفات بالرياض
شركة تنظيف مكيفات اسبلت بالرياض
افضل شركة غسيل مكيفات اسبلت بالرياض
شركة كشف تسربات المياه بالرياض
افضل شركة كشف تسربات المياه بالرياض

cara menggugurkan kandungan secara tradisional said...

just information we only provide information for those who need it

Tangki Fiber said...

You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks
Tangki Panel
Tangki Fiberglass
Jual Septic Tank
Tangki Kimia
Jual Talang Fiber
Jual Rotameter
jual mesin ro
Jual Botol Plastik Agro

Jual Botol Plastik Murah

Sophie Grace said...

This is a great blog, I enjoy reading your blog very much! Please dont stop! deskgram

Unknown said...

www1016
ralph lauren polo
christian louboutin
ralph lauren polo
coach outlet
adidas clothing
reebok outlet
canada goose clothing
ralph lauren uk
coach outlet
jordan shoes

yanmaneee said...

kd 11
gucci belt
nike air force 1
balenciaga shoes
kobe byrant shoes
air jordan shoes
yeezy boost 350
lacoste polo
yeezy sneakers
off white

Devi.Angularjs said...

The effectiveness of IEEE Project Domains depends very much on the situation in which they are applied. In order to further improve IEEE Final Year Project Domains practices we need to explicitly describe and utilise our knowledge about software domains of software engineering Final Year Project Domains for CSE technologies. This paper suggests a modelling formalism for supporting systematic reuse of software engineering technologies during planning of software projects and improvement programmes in Final Year Project Centers in Chennai.

Software management seeks for decision support to identify technologies like JavaScript that meet best the goals and characteristics of a software project or improvement programme. JavaScript Training in Chennai Accessible experiences and repositories that effectively guide that technology selection are still lacking.

Aim of technology domain analysis is to describe the class of context situations (e.g., kinds of JavaScript software projects) in which a software engineering technology JavaScript Training in Chennai can be applied successfully

jasa website gembling said...


jasa seo indonesia


agen bola

Poker online
Poker Uang Asli


Prediksi Bola
Jadwal Bola
Agen Bola



dominoqq
bandarqq
poker qq online
pkv games

yanmaneee said...

supreme outlet
golden goose sale
balenciaga
golden goose
goyard bags
golden goose
supreme
golden goose sneakers
goyard handbags
golden goose outlet

yanmaneee said...

supreme outlet
off white nike
moncler jackets
yeezy boost 700
adidas ultra boost
moncler coat
chrome hearts outlet
louboutin shoes
supreme outlet
supreme clothing

Awad Elsayed said...


تعد شركتنا من افضل الشركات المتخصصة في تنظيف خزانات ومن الجدير بالذكر ان شركتنا تتمتع بالمصداقية والقدرة على انجاز العمل ، كما ان شركتنا تتمكن من العمل تحت أي ضغط وفي ظل أي ظرف وشركتنا تضم افضل المعدات الحديثة والأساليب المتطورة والطرق الحديثة والخبرات الفائقة لكي تقوم بإجراء جميع عمليات التنظيف الشاملة للخزانات وتعقيمها على النحو المطلوب، كما تهتم شركتنا بمتابعة جميع عمليات التنظيف اليت قامت بها شهريًا من أجل الحصول على النتائج المطلوبة.
شركة كشف تسربات المياه بسراة عبيدة

شركة عزل خزانات بسراة عبيدة

شركة عزل اسطح بسراة عبيدة

شركة تنظيف خزانات بسراة عبيدة

شركة تنظيف بسراة عبيدة

seoexpert said...

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject?play tetris unblocked

عبدالله هادى said...


شركة تنظيف شقق بالرياض
شركة تنظيف واجهات زجاج بالرياض
شركة تنظيف موكيت بالرياض
شركة عزل خزانات بالرياض

Bandar Togel Online said...

menangkan games di bandar togel online kingdomgrup bosku ada bonus nya http://128.199.187.54/

EASlot said...

Situs Slot Online Deposit Pulsa Tanpa Potongan

Mainkan Slot Online Deposit Pulsa Hanya Ada Disini

Goaloo said...

Ayok Cek hasil score hanya di http://goaloo.co.id/

daidowadford said...

PS Plus free games - Snk21 News
PS Plus free games · Plants vs. Zombies: Battle for Neighborville · Battlefield V 카지노사이트 · Street 바카라사이트 Fighter II: The New Challengers · Super Hang