Atomic updates

bearophile bearophileHUGS at lycos.com
Tue Jan 22 03:15:58 PST 2013


monarch_dodra:

> That's a good point, and I'm sure we could also have a version 
> of D that could also do it that way.

Someone is willing to create that second version for RosettaCode?

I have modified a bit the second and third Go versions on 
Rosettacode, now there are 20 buckets and it shows the print 
every 1 second (like the D version currently present on 
Rosettacode). I have compiled the Go code with the latest go1.0.3 
(that is a fast compiler, but I think it doesn't produce a very 
efficient binary). The outputs:

Go atomic2b:
sum  ---updates---    mean  buckets
1000   825883   825883  1651766  [96 19 7 45 119 35 67 4 45 19 
106 51 19 69 8 102 34 47 56 52]
1000   754038   754037  1579920  [27 92 16 9 17 34 74 26 69 20 
110 120 38 16 93 10 131 8 34 56]
1000   815841   815842  1597174  [27 10 46 54 32 19 55 87 125 87 
46 29 70 57 37 2 14 151 2 50]
1000   748939   748938  1572350  [78 52 82 64 12 6 15 36 13 103 
52 21 12 55 58 137 100 69 16 19]
1000   748836   748837  1557414  [78 79 29 114 13 12 131 105 22 
20 68 77 40 19 68 30 36 57 1 1]
1000   751092   751092  1548209  [23 17 35 106 58 74 40 141 35 
124 3 46 32 46 0 47 32 37 57 47]
1000   747933   747933  1540732  [43 32 31 32 29 36 41 46 37 51 
46 1 48 263 37 61 51 61 43 11]


Go atomic3b
sum  ---updates---    mean  buckets
1000  1098238  1098238  2196476  [93 22 4 122 48 20 52 37 50 73 
13 22 85 103 93 22 2 13 86 40]
1000   907417   907417  2005655  [36 57 36 134 6 48 21 134 47 76 
18 65 22 18 61 92 67 15 23 24]
1000   814198   814197  1879901  [21 51 56 37 55 36 22 50 106 0 
99 6 59 107 55 21 40 67 65 47]
1000   725805   725805  1772828  [32 5 105 39 123 17 46 23 25 38 
24 104 109 51 87 32 13 1 39 87]
1000   793476   793476  1735653  [65 24 63 62 88 59 57 99 27 47 
25 70 30 4 31 0 57 89 24 79]
1000   837247   837247  1725460  [23 28 95 35 31 37 105 40 15 13 
46 53 36 17 36 134 50 76 94 36]
1000   991714   991714  1762312  [20 86 116 42 32 52 59 11 55 49 
41 102 82 59 17 7 7 28 31 104]
1000   838766   838767  1751715  [18 29 15 17 31 140 12 42 52 90 
53 136 57 42 31 73 31 44 43 44]
1000   764370   764370  1726940  [64 5 78 77 127 90 43 14 46 0 46 
70 63 20 42 57 3 20 58 77]


D version (-O -release -inline -noboundscheck):
n. randomize, n. equalize, buckets, buckets sum:
409363 2 [47, 0, 70, 77, 9, 0, 70, 36, 130, 24, 53, 64, 52, 17, 
56, 65, 116, 65, 17, 40] 1008
2318049 2265054 [51, 51, 51, 51, 51, 51, 51, 50, 51, 51, 51, 51, 
51, 51, 51, 51, 51, 51, 51, 40] 1008
2063793 2447437 [9, 0, 196, 76, 0, 2, 60, 36, 23, 40, 17, 44, 0, 
29, 156, 16, 147, 76, 41, 40] 1008
2010050 2579035 [51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 
51, 51, 51, 51, 51, 50, 51, 40] 1008
2180213 2151695 [152, 130, 12, 46, 6, 5, 10, 0, 0, 130, 109, 11, 
73, 39, 15, 72, 0, 60, 98, 40] 1008
1930470 2646068 [50, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 
51, 51, 51, 51, 51, 51, 51, 40] 1008
1967369 2650625 [64, 17, 16, 260, 29, 50, 94, 128, 65, 24, 49, 
30, 42, 0, 35, 9, 28, 15, 13, 40] 1008


To compile the second Go version you need:

import (
     "fmt"
     "math/rand"
     "time"
     "sync"
     "runtime"
)
...
func main() {
     // Create a concrete object implementing the bucketList 
interface.
     bl := newRwList(20, originalTotal, nUpdaters)


And for the third:

import (
     "fmt"
     "math/rand"
     "time"
     "sync"
     "runtime"
     "sync/atomic"
)
...
func main() {
     // Create a concrete object implementing the bucketList 
interface.
     bl := newLfList(20, originalTotal, nUpdaters)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list