Code Monkey home page Code Monkey logo

fastlane-1's Introduction

fastlane

Build Status GoDoc

Fast single-producer / single-consumer channels for Go.

A fastlane channel works similar to a standard Go channel with the following exceptions:

  • It does not have a close method. A sender must send the receiver a custom close message.
  • It's unbounded and has no buffering. There's lock-free linked list under the hood.
  • It expects to be communicating over a maximum of two goroutines. One for Send and one for Recv.

Getting Started

Installing

To start using fastlane, install Go and run go get:

$ go get -u github.com/tidwall/fastlane

This will retrieve the library.

Usage

There're only two functions Send and Recv.

// chan.go
package main

import "github.com/tidwall/fastlane"

func main() {
	var ch fastlane.Chan

	go func() { ch.Send("ping") }()

	v := ch.Recv()
	println(v.(string))
}
$ go run chan.go 
ping

Performance

The benchmark tests the speed of sending integers between two goroutines.

$ go test -run none -bench .

MacBook Pro 15" 2.8 GHz Intel Core i7 (darwin/amd64)

BenchmarkFastlaneChan-8   	20000000	        72.7 ns/op
BenchmarkGoChan-8         	 5000000	       241 ns/op

Mac mini i7-3615QM CPU @ 2.30GHz (linux/amd64)

BenchmarkFastlaneChan-8   	10000000	       105 ns/op
BenchmarkGoChan-8         	 3000000	       602 ns/op

Raspberry Pi 3 (linux/arm64)

BenchmarkFastlaneChan-4   	 5000000	       393 ns/op
BenchmarkGoChan-4         	 1000000	      1337 ns/op

Raspberry Pi 3 (linux/arm)

BenchmarkFastlaneChan-4   	 3000000	       535 ns/op
BenchmarkGoChan-4         	 1000000	      2195 ns/op

Contact

Josh Baker @tidwall

License

fastlane source code is available under the MIT License.

fastlane-1's People

Contributors

tidwall avatar

Watchers

 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.