1 /* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.eventbus; 18 19 import com.google.caliper.BeforeExperiment; 20 import com.google.caliper.Benchmark; 21 22 /** 23 * Benchmark for {@link EventBus}. 24 * 25 * @author Eric Fellheimer 26 */ 27 public class EventBusBenchmark { 28 29 private EventBus eventBus; 30 31 @BeforeExperiment 32 void setUp() { 33 eventBus = new EventBus("for benchmarking purposes"); 34 eventBus.register(this); 35 } 36 37 @Benchmark void postStrings(int reps) { 38 for (int i = 0; i < reps; i++) { 39 eventBus.post("hello there"); 40 } 41 } 42 43 @Subscribe 44 public void handleStrings(String string) { 45 // Nothing to do here. 46 } 47 } 48