/**
  * @param array $data
  * @return array
  */
 public function run(array $data)
 {
     switch ($data['adapter']) {
         case 'mysql':
             $connection = DriverManager::getConnection($data['options']);
             $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             $adapter = new DoctrineEventStoreAdapter($connection, new FQCNMessageFactory(), new NoOpMessageConverter(), new JsonPayloadSerializer());
             break;
         case 'postgres':
             $connection = DriverManager::getConnection($data['options']);
             $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             $adapter = new DoctrineEventStoreAdapter($connection, new FQCNMessageFactory(), new NoOpMessageConverter(), new JsonPayloadSerializer());
             break;
         case 'mongodb':
             $connection = new \MongoClient($data['options']['server']);
             $connection->selectDB('event_store_adapter_benchmarks')->selectCollection('user_stream')->drop();
             $adapter = new MongoDbEventStoreAdapter(new FQCNMessageFactory(), new NoOpMessageConverter(), $connection, $data['options']['db_name']);
             break;
         default:
             throw new \InvalidArgumentException('invalid adapter given');
             break;
     }
     $eventStore = new EventStore($adapter, new ProophActionEventEmitter());
     $result = [];
     foreach ($data['batchSizes'] as $batchSize) {
         for ($i = 0; $i < $this->repeats; $i++) {
             $events = [];
             $start = microtime(true);
             for ($b = 1; $b <= $batchSize * 2; $b++) {
                 $v1 = $b;
                 $b++;
                 $v2 = $b;
                 $events[] = UserCreated::with(['name' => 'Max Mustermann ' . $i . '-' . $b, 'email' => 'contact' . $i . '-' . $b . '@prooph.de'], $v1);
                 $events[] = UsernameChanged::with(['name' => 'John Doe ' . $i . '-' . $b], $v2);
             }
             $eventStore->beginTransaction();
             $eventStore->create(new Stream(new StreamName('user_stream'), new \ArrayIterator($events)));
             $eventStore->commit();
             $end = microtime(true);
             if ($connection instanceof Connection) {
                 $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             } else {
                 $connection->selectDB('event_store_adapter_benchmarks')->selectCollection('user_stream')->drop();
             }
             $diff = $end - $start;
             $result[$data['adapter'] . ' with batch size ' . $batchSize] = $diff;
         }
     }
     return $result;
 }