aboutsummaryrefslogtreecommitdiffstats
path: root/event/event_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-07-19 07:39:12 +0800
committerFelix Lange <fjl@twurst.com>2017-01-26 01:44:20 +0800
commit6d5e100d0dc6fc0b905610850a75b5d4fa907739 (patch)
treea653dc592af1e7405faeaf9ec9b84f9b32aa3b88 /event/event_test.go
parent9b62facdd4bdabfed5ef98d131686c4d2606083a (diff)
downloadgo-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar.gz
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar.bz2
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar.lz
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar.xz
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.tar.zst
go-tangerine-6d5e100d0dc6fc0b905610850a75b5d4fa907739.zip
event: add new Subscription type and related utilities
This commit introduces a new Subscription type, which is synonymous with ethereum.Subscription. It also adds a couple of utilities that make working with Subscriptions easier. The mot complex utility is Feed, a synchronisation device that implements broadcast subscriptions. Feed is slightly faster than TypeMux and will replace uses of TypeMux across the go-ethereum codebase in the future.
Diffstat (limited to 'event/event_test.go')
-rw-r--r--event/event_test.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/event/event_test.go b/event/event_test.go
index 2c56ecf29..a12945a47 100644
--- a/event/event_test.go
+++ b/event/event_test.go
@@ -149,16 +149,34 @@ func emptySubscriber(mux *TypeMux, types ...interface{}) {
}()
}
-func BenchmarkPost3(b *testing.B) {
- var mux = new(TypeMux)
- defer mux.Stop()
- emptySubscriber(mux, testEvent(0))
- emptySubscriber(mux, testEvent(0))
- emptySubscriber(mux, testEvent(0))
+func BenchmarkPost1000(b *testing.B) {
+ var (
+ mux = new(TypeMux)
+ subscribed, done sync.WaitGroup
+ nsubs = 1000
+ )
+ subscribed.Add(nsubs)
+ done.Add(nsubs)
+ for i := 0; i < nsubs; i++ {
+ go func() {
+ s := mux.Subscribe(testEvent(0))
+ subscribed.Done()
+ for range s.Chan() {
+ }
+ done.Done()
+ }()
+ }
+ subscribed.Wait()
+ // The actual benchmark.
+ b.ResetTimer()
for i := 0; i < b.N; i++ {
mux.Post(testEvent(0))
}
+
+ b.StopTimer()
+ mux.Stop()
+ done.Wait()
}
func BenchmarkPostConcurrent(b *testing.B) {