This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
"path/filepath" | |
"strings" | |
"sync" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i := 0; i < b.N; i++ { | |
b.StopTimer() | |
chans := make([]<-chan int, n) | |
for j := range chans { | |
chans[j] = asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) | |
} | |
b.StartTimer() | |
c := merge.fun(chans...) | |
for range c { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
ns = [2**x for x in range(11)]; | |
data = { | |
'goroutines': [6919, 13212, 25469, 50819, 88566, 162391, 299955, 574043, 1129372, 2251411, 4760560], | |
'reflection': [10868, 22335, 54882, 148218, 543921, 1694021, 6102920, 22648976, 90204929, 383579039, 1676544681], | |
'recursion': [2658, 14707, 44520, 114676, 261880, 560284, 1117642, 2242910, 4784719, 10044186, 20599475], | |
} | |
for (label, values) in data.items(): | |
plt.plot(ns, values, label=label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMerge(b *testing.B) { | |
merges := []struct { | |
name string | |
fun func(...<-chan int) <-chan int | |
}{ | |
{"goroutines", merge}, | |
{"reflect", mergeReflect}, | |
{"recursion", mergeRec}, | |
} | |
for _, merge := range merges { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMerge(b *testing.B) { | |
merges := []struct { | |
name string | |
fun func(...<-chan int) <-chan int | |
}{ | |
{"goroutines", merge}, | |
{"reflect", mergeReflect}, | |
{"recursion", mergeRec}, | |
} | |
for _, merge := range merges { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMerge(b *testing.B) { | |
merges := []func(...<-chan int) <-chan int{ | |
merge, | |
mergeReflect, | |
mergeRec, | |
} | |
for _, merge := range merges { | |
for i := 0; i < b.N; i++ { | |
c := merge(asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | |
for range c { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMergeRec(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
c := mergeRec(asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | |
for range c { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMergeReflect(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
c := mergeReflect(asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | |
for range c { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMergeReflect(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
c := mergeReflect(asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | |
for range c { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BenchmarkMerge(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
c := merge(asChan(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) | |
for range c { | |
} | |
} | |
} |