goid

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 0 Imported by: 4

README

Getting Started

An out of box example. playground

package main

import (
	"github.com/phuslu/goid"
)

func main() {
	println(goid.Goid())
}

// Output:
//   1

Performance

// go test -v -cpu=1 -run=none -bench=. -benchtime=10s -benchmem bench_test.go
package main

import (
	"testing"

	choleraehyq "github.com/choleraehyq/pid"
	petermattis "github.com/petermattis/goid"
	phuslu "github.com/phuslu/goid"
)

func BenchmarkCholeraehyq(b *testing.B) {
	for i := 0; i < b.N; i++ {
		choleraehyq.Get()
	}
}

func BenchmarkPetermattis(b *testing.B) {
	for i := 0; i < b.N; i++ {
		petermattis.Get()
	}
}

func BenchmarkPhuslu(b *testing.B) {
	for i := 0; i < b.N; i++ {
		phuslu.Goid()
	}
}

A Performance result as below, for daily benchmark results see github actions

goos: linux
goarch: amd64
pkg: bench
cpu: AMD EPYC 7763 64-Core Processor                
BenchmarkCholeraehyq
BenchmarkCholeraehyq 	1000000000	         1.866 ns/op	       0 B/op	       0 allocs/op
BenchmarkPetermattis
BenchmarkPetermattis 	1000000000	         1.858 ns/op	       0 B/op	       0 allocs/op
BenchmarkPhuslu
BenchmarkPhuslu      	1000000000	         1.858 ns/op	       0 B/op	       0 allocs/op
PASS
ok  	bench	6.151s

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Goid

func Goid() int64

Goid returns the current goroutine id. It exactly matches goroutine id of the stack trace.

Example
fmt.Println(Goid())
Output:

1

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL