root/trunk/benchmark/cheapconcurrency.md

Revision 362, 0.6 kB (checked in by JarrettBillingsley, 3 months ago)

Fixed a bug where array data was being allocated but not initialized, causing some GC cycles to try to scan garbage data (and crash). Updated the benchmarks and all that I've tested have worked fine, not to mention being at least 15% faster in most cases :)

Line 
1 module cheapconcurrency
2
3 // n = 3000, 3.566 sec (very good, and on my desktop at that!!)
4 // on my laptop: 1.128 sec!!
5
6 function link(n)
7 {
8     if(n > 1)
9     {
10         local cofunc = coroutine link
11         cofunc(n - 1)
12         yield()
13
14         while(true)
15             yield(cofunc() + 1)
16     }
17     else
18     {
19         while(true)
20             yield(1)
21     }
22 }
23
24 function main(N)
25 {
26     local n = 3000
27
28     if(isString(N))
29         try n = toInt(N); catch(e) {}
30
31     local timer = time.Timer.clone()
32     timer.start()
33
34     local cofunc = coroutine link
35     cofunc(500)
36     local count = 0
37
38     for(i : 0 .. n)
39         count += cofunc()
40
41     writefln(count)
42
43     timer.stop()
44     writefln("Took {} sec", timer.seconds())
45 }
Note: See TracBrowser for help on using the browser.