Created
February 27, 2015 01:15
-
-
Save lestrrat/00a912254a78e003aefc to your computer and use it in GitHub Desktop.
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
wg := &sync.WaitGroup{} | |
ch := make(chan struct{}) | |
for i := 0; i < 100; i++ { | |
wg.Add(1) | |
go func(ch chan struct{}) { | |
defer wg.Done() | |
for _ = range ch { | |
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name}) | |
if err != nil { | |
log.Fatalf("could not greet: %v", err) | |
} | |
log.Printf("Greeting: %s", r.Message) | |
} | |
}(ch) | |
} | |
numJobs := 10000 | |
start := time.Now() | |
for i := 0; i < numJobs; i++ { | |
ch <- struct{}{} | |
} | |
close(ch) | |
fmt.Printf("Waiting for workers...\n") | |
wg.Wait() | |
elapsed := time.Since(start) | |
fmt.Printf("%d jobs in %0.2f seconds (%0.2f jobs/sec)\n", numJobs, float64(elapsed)/float64(time.Second), float64(numJobs)/(float64(elapsed)/float64(time.Second))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment