vendor lotsa package
This commit is contained in:
parent
546e7a0ad2
commit
0aa04a1910
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@ -138,6 +138,12 @@
|
||||
packages = ["."]
|
||||
revision = "ba9a043346eba55344e40d66a5e74cfda3a9d293"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/tidwall/lotsa"
|
||||
packages = ["."]
|
||||
revision = "a03631ac7f1cd37f159fca01ff6d600b3536d3cf"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/tidwall/match"
|
||||
@ -231,6 +237,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "d03f1946a6c426327998ec09c8ed935b234a8ca47e2bea55dd6f9d77424f0d60"
|
||||
inputs-digest = "815f293904a566198a4157c81abad0db57c378fad869347de42c2201795b2158"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
@ -21,6 +21,8 @@
|
||||
# version = "2.4.0"
|
||||
|
||||
|
||||
required = ["github.com/tidwall/lotsa"]
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/Shopify/sarama"
|
||||
version = "1.13.0"
|
||||
|
20
vendor/github.com/tidwall/lotsa/LICENSE
generated
vendored
Normal file
20
vendor/github.com/tidwall/lotsa/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Josh Baker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
33
vendor/github.com/tidwall/lotsa/README.md
generated
vendored
Normal file
33
vendor/github.com/tidwall/lotsa/README.md
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# lotsa
|
||||
|
||||
Lotsa is a simple Go library for executing lots of operations spread over any number of threads.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
go get -u github.com/tidwall/lotsa
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
Here we load 1,000,000 operations spread over 4 threads.
|
||||
|
||||
```
|
||||
var total int64
|
||||
lotsa.Ops(1000000, 4,
|
||||
func(i, thread int) {
|
||||
atomic.AddInt64(&total, 1)
|
||||
},
|
||||
)
|
||||
println(total)
|
||||
```
|
||||
|
||||
Prints `1000000`
|
||||
|
||||
## Contact
|
||||
|
||||
Josh Baker [@tidwall](http://twitter.com/tidwall)
|
||||
|
||||
## License
|
||||
|
||||
Source code is available under the MIT [License](/LICENSE).
|
59
vendor/github.com/tidwall/lotsa/lotsa.go
generated
vendored
Normal file
59
vendor/github.com/tidwall/lotsa/lotsa.go
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
package lotsa
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Output is used to print elased time and ops/sec
|
||||
var Output io.Writer
|
||||
|
||||
// Ops executed a number of operations over a multiple goroutines.
|
||||
// count is the number of operations.
|
||||
// threads is the number goroutines.
|
||||
// op is the operation function
|
||||
func Ops(count, threads int, op func(i, thread int)) {
|
||||
var start time.Time
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(threads)
|
||||
output := Output
|
||||
if output != nil {
|
||||
start = time.Now()
|
||||
}
|
||||
for i := 0; i < threads; i++ {
|
||||
s, e := count/threads*i, count/threads*(i+1)
|
||||
if i == threads-1 {
|
||||
e = count
|
||||
}
|
||||
go func(i, s, e int) {
|
||||
defer wg.Done()
|
||||
for j := s; j < e; j++ {
|
||||
op(j, i)
|
||||
}
|
||||
}(i, s, e)
|
||||
}
|
||||
wg.Wait()
|
||||
if output != nil {
|
||||
dur := time.Since(start)
|
||||
var ss string
|
||||
if threads != 1 {
|
||||
ss = fmt.Sprintf("over %d threads ", threads)
|
||||
}
|
||||
fmt.Fprintf(output, "%s ops %sin %.0fms %s/sec\n",
|
||||
commaize(count), ss, dur.Seconds()*1000,
|
||||
commaize(int(float64(count)/dur.Seconds())))
|
||||
}
|
||||
}
|
||||
|
||||
func commaize(n int) string {
|
||||
s1, s2 := fmt.Sprintf("%d", n), ""
|
||||
for i, j := len(s1)-1, 0; i >= 0; i, j = i-1, j+1 {
|
||||
if j%3 == 0 && j != 0 {
|
||||
s2 = "," + s2
|
||||
}
|
||||
s2 = string(s1[i]) + s2
|
||||
}
|
||||
return s2
|
||||
}
|
18
vendor/github.com/tidwall/lotsa/lotsa_test.go
generated
vendored
Normal file
18
vendor/github.com/tidwall/lotsa/lotsa_test.go
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
package lotsa
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOps(t *testing.T) {
|
||||
var threads = 4
|
||||
var N = threads * 10000
|
||||
var total int64
|
||||
Ops(N, threads, func(i, thread int) {
|
||||
atomic.AddInt64(&total, 1)
|
||||
})
|
||||
if total != int64(N) {
|
||||
t.Fatal("invalid total")
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user