Code Monkey home page Code Monkey logo

gompool's Introduction

gompool

gompool is a simple allocation-free and lock-free memory pool library written in golang using treiber stack

Requirement

  • go (>= 1.8)

Installation

go get github.com/hlts2/gompool

Example

// Create 10 pools of `*bytes.Buffer`
pools := gompool.NewGompool(10, func() interface{} {
    return &bytes.Buffer{}
})

pool1 := pools.Get()
pool2 := pools.Get()

buf1 := pool1.Value.(*bytes.Buffer)
buf1.WriteString("Hello world1")

buf2 := pool2.Value.(*bytes.Buffer)
buf2.WriteString("Hello world2")

pools.Put(pool1)    // Return pool1 to pools
pools.Put(pool2)    // Return pool2 to pools

Benchmark

gompool vs sync.Pool(Standard library)

goos: darwin
goarch: amd64
pkg: github.com/hlts2/gompool
BenchmarkGompool-4       	30000000	        54.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkGompool-4       	30000000	        54.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGompool-4       	30000000	        55.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGompool-4       	30000000	        54.2 ns/op	       0 B/op	       0 allocs/op
BenchmarkGompool-4       	30000000	        53.7 ns/op	       0 B/op	       0 allocs/op
BenchmarkDefaultPool-4   	20000000	        66.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkDefaultPool-4   	20000000	        67.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkDefaultPool-4   	20000000	        67.4 ns/op	       0 B/op	       0 allocs/op
BenchmarkDefaultPool-4   	20000000	        68.0 ns/op	       0 B/op	       0 allocs/op
BenchmarkDefaultPool-4   	20000000	        68.1 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	github.com/hlts2/gompool	15.530s

Author

hlts2

LICENSE

gompool released under MIT license, refer LICENSE file.

gompool's People

Contributors

hlts2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gompool's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.