Giter Club home page Giter Club logo

abool's Introduction

ABool ๐Ÿ’ก

GoDoc

Atomic Boolean library for Golang, optimized for performance yet simple to use.

Use this for cleaner code.

Usage

import "github.com/tevino/abool"

cond := abool.New()  // default to false

cond.Set()                 // Set to true
cond.IsSet()               // Returns true
cond.UnSet()               // Set to false
cond.SetTo(true)           // Set to whatever you want
cond.SetToIf(false, true)  // Set to true if it is false, returns false(not set)


// embedding
type Foo struct {
    cond *abool.AtomicBool  // always use pointer to avoid copy
}

Benchmark:

  • Golang 1.6.2
  • OS X 10.11.4
# Read
BenchmarkMutexRead-4       	100000000	        21.0 ns/op
BenchmarkAtomicValueRead-4 	200000000	         6.30 ns/op
BenchmarkAtomicBoolRead-4  	300000000	         4.21 ns/op  # <--- This package

# Write
BenchmarkMutexWrite-4      	100000000	        21.6 ns/op
BenchmarkAtomicValueWrite-4	 30000000	        43.4 ns/op
BenchmarkAtomicBoolWrite-4 	200000000	         9.87 ns/op  # <--- This package

# CAS
BenchmarkMutexCAS-4        	 30000000	        44.9 ns/op
BenchmarkAtomicBoolCAS-4   	100000000	        11.7 ns/op   # <--- This package

abool's People

Contributors

tevino avatar

Watchers

 avatar  avatar  avatar

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.