func (c *Client) Run(res chan *RunResults) {
	newMsgs := make(chan *Message)
	pubMsgs := make(chan *Message)
	doneGen := make(chan bool)
	donePub := make(chan bool)
	runResults := new(RunResults)
	started := time.Now()
	go c.genMessages(newMsgs, doneGen)
	go c.pubMessages(newMsgs, pubMsgs, doneGen, donePub)
	runResults.ID = c.ID
	times := []float64{}
	for {
		select {
		case m := <-pubMsgs:
			if m.Error {
				log.Printf("CLIENT %v ERROR publishing message: %v: at %v\n", c.ID, m.Topic, m.Sent.Unix())
				runResults.Failures++
			} else {
				runResults.Successes++
				times = append(times, m.Delivered.Sub(m.Sent).Seconds()*1000)  
			}
		case <-donePub:
			duration := time.Since(started)
			runResults.MsgTimeMin = stats.StatsMin(times)
			runResults.MsgTimeMax = stats.StatsMax(times)
			runResults.MsgTimeMean = stats.StatsMean(times)
			runResults.RunTime = duration.Seconds()
			runResults.MsgsPerSec = float64(runResults.Successes) / duration.Seconds()
			if c.MsgCount > 1 {
				runResults.MsgTimeStd = stats.StatsSampleStandardDeviation(times)
			}
			res <- runResults
			return
		}
	}
}
Run runs benchmark tests and writes results in the provided channel
package main
import (
	"crypto/tls"
	"fmt"
	"log"
	"time"
	"github.com/GaryBoone/GoStats/stats"
	mqtt "github.com/eclipse/paho.mqtt.golang"
)
type Client struct {
	ID          int
	ClientID    string
	BrokerURL   string
	BrokerUser  string
	BrokerPass  string
	MsgTopic    string
	MsgPayload  string
	MsgSize     int
	MsgCount    int
	MsgQoS      byte
	Quiet       bool
	WaitTimeout time.Duration
	TLSConfig   *tls.Config
}