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 { | |
} | |
} | |
} |
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 BenchmarkFoo(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
// perform the operation we're analyzing | |
} | |
} |
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 mergeRec(chans ...<-chan int) <-chan int { | |
switch len(chans) { | |
case 0: | |
c := make(chan int) | |
close(c) | |
return c | |
case 1: | |
return chans[0] | |
default: | |
m := len(chans) / 2 |
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
\documentclass[conference,10pt]{IEEEtran} | |
\usepackage[utf8]{inputenc} | |
\ifCLASSINFOpdf | |
\usepackage[pdftex]{graphicx} | |
\else | |
\usepackage[dvips]{graphicx} | |
\fi | |
\usepackage{algpseudocode} | |
\usepackage{amsmath} | |
\usepackage{color} |
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 merge(cs ...<-chan int) <-chan int { | |
out := make(chan int) | |
var wg sync.WaitGroup | |
wg.Add(len(cs)) | |
for _, c := range cs { | |
go func(c <-chan int) { | |
for v := range c { | |
out <- v | |
} | |
wg.Done() |
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
i, v, ok := reflect.Select(cases) | |
if !ok { | |
cases = append(cases[:i], cases[i+1:]...) | |
continue | |
} | |
out <- v.Interface().(int) |
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
i, v, ok := reflect.Select(cases) | |
if !ok { | |
cases = append(cases[:i], cases[i+1:]...) | |
continue | |
} | |
out <- v.Interface().(int) |
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
var cases []reflect.SelectCase | |
for _, c := range chans { | |
cases = append(cases, reflect.SelectCase{ | |
Dir: reflect.SelectRecv, | |
Chan: reflect.ValueOf(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 merge(cs ...<-chan int) <-chan int { | |
out := make(chan int) | |
var wg sync.WaitGroup | |
wg.Add(len(cs)) | |
for _, c := range cs { | |
go func(c <-chan int) { | |
for v := range c { | |
out <- v | |
} | |
wg.Done() |