Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
bg5sbk committed Jan 11, 2016
1 parent eb9f8cf commit 4cf250b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 67 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ pool.Free(buf)
Performance
===========

When `GOMAXPROCS=16`:
Result of `GOMAXPROCS=16 go test -v -bench=. -benchmem`:

```
Benchmark_AtomPool_AllocAndFree_128-4 10000000 183 ns/op 0 B/op 0 allocs/op
Benchmark_AtomPool_AllocAndFree_256-4 10000000 185 ns/op 0 B/op 0 allocs/op
Benchmark_AtomPool_AllocAndFree_512-4 10000000 183 ns/op 0 B/op 0 allocs/op
Benchmark_AtomPool_AllocAndFree_128-16 10000000 185 ns/op 0 B/op 0 allocs/op
Benchmark_AtomPool_AllocAndFree_256-16 10000000 181 ns/op 0 B/op 0 allocs/op
Benchmark_AtomPool_AllocAndFree_512-16 10000000 176 ns/op 0 B/op 0 allocs/op
Benchmark_SyncPool_AllocAndFree_128-4 20000000 66.2 ns/op 32 B/op 1 allocs/op
Benchmark_SyncPool_AllocAndFree_256-4 20000000 68.8 ns/op 32 B/op 1 allocs/op
Benchmark_SyncPool_AllocAndFree_512-4 20000000 69.7 ns/op 32 B/op 1 allocs/op
Benchmark_SyncPool_AllocAndFree_128-16 20000000 92.6 ns/op 32 B/op 1 allocs/op
Benchmark_SyncPool_AllocAndFree_256-16 20000000 76.6 ns/op 32 B/op 1 allocs/op
Benchmark_SyncPool_AllocAndFree_512-16 20000000 81.3 ns/op 32 B/op 1 allocs/op
Benchmark_Make_128-4 30000000 48.1 ns/op 128 B/op 1 allocs/op
Benchmark_Make_256-4 20000000 74.5 ns/op 256 B/op 1 allocs/op
Benchmark_Make_512-4 10000000 101 ns/op 512 B/op 1 allocs/op
Benchmark_Make_128-16 20000000 52.9 ns/op 128 B/op 1 allocs/op
Benchmark_Make_256-16 20000000 97.1 ns/op 256 B/op 1 allocs/op
Benchmark_Make_512-16 10000000 128 ns/op 512 B/op 1 allocs/op
```
57 changes: 0 additions & 57 deletions atom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,63 +63,6 @@ func Test_AtomPool_AllocSlow(t *testing.T) {
utest.EqualNow(t, cap(mem), 1024)
}

func Test_AtomPool_AllocAndFree(t *testing.T) {
pool := NewAtomPool(128, 64*1024, 2, 1024*1024)
for i := 0; i < len(pool.classes); i++ {
temp := make([][]byte, len(pool.classes[i].chunks))

for j := 0; j < len(temp); j++ {
mem := pool.Alloc(pool.classes[i].size)
utest.EqualNow(t, cap(mem), pool.classes[i].size)
temp[j] = mem
}
utest.Assert(t, pool.classes[i].head == 0)

for j := 0; j < len(temp); j++ {
pool.Free(temp[j])
}
utest.Assert(t, pool.classes[i].head != 0)
}
}

func Test_AtomPool_AllocSmall(t *testing.T) {
pool := NewAtomPool(128, 1024, 2, 1024)
mem := pool.Alloc(64)
utest.EqualNow(t, len(mem), 64)
utest.EqualNow(t, cap(mem), 128)
pool.Free(mem)
}

func Test_AtomPool_AllocLarge(t *testing.T) {
pool := NewAtomPool(128, 1024, 2, 1024)
mem := pool.Alloc(2048)
utest.EqualNow(t, len(mem), 2048)
utest.EqualNow(t, cap(mem), 2048)
pool.Free(mem)
}

func Test_AtomPool_DoubleFree(t *testing.T) {
pool := NewAtomPool(128, 1024, 2, 1024)
mem := pool.Alloc(64)
go func() {
defer func() {
utest.NotNilNow(t, recover())
}()
pool.Free(mem)
pool.Free(mem)
}()
}

func Test_AtomPool_AllocSlow(t *testing.T) {
pool := NewAtomPool(128, 1024, 2, 1024)
mem := pool.classes[len(pool.classes)-1].Pop()
utest.EqualNow(t, cap(mem), 1024)
utest.Assert(t, pool.classes[len(pool.classes)-1].head == 0)

mem = pool.Alloc(1024)
utest.EqualNow(t, cap(mem), 1024)
}

func Benchmark_AtomPool_AllocAndFree_128(b *testing.B) {
pool := NewAtomPool(128, 1024, 2, 64*1024)
b.ResetTimer()
Expand Down

0 comments on commit 4cf250b

Please sign in to comment.