Skip to content

Instantly share code, notes, and snippets.

@FZambia
Last active September 5, 2015 13:45
Show Gist options
  • Save FZambia/3f913e4adf0ef3293a34 to your computer and use it in GitHub Desktop.
Save FZambia/3f913e4adf0ef3293a34 to your computer and use it in GitHub Desktop.
Measure time
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/centrifugal/centrifugo/libcentrifugo/stringqueue"
)
func main() {
// Prepare.
nElems := 1000
nConns := 100
nAdds := nElems * nConns
// Slice of abstract messages.
elems := make([]map[string]string, nElems)
for i := 0; i < nElems; i++ {
elems[i] = map[string]string{
"method": "test",
"params": "here is test message",
}
}
// Input data for a queue.
s := make([]string, nAdds)
for i := 0; i < nAdds; i++ {
s[i] = "a"
}
// Start measuring.
start := time.Now()
// Encode.
jsonData, _ := json.Marshal(elems)
// Add to queue.
q := stringqueue.New()
for _, el := range s {
err := q.Add(el)
if !err {
println(err)
}
}
// Decode.
var data interface{}
json.Unmarshal(jsonData, &data)
fmt.Printf("%s", time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment