fbsc

package module
v0.0.0-...-c0f4884 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: Unlicense Imports: 1 Imported by: 0

README

fbsc (Fast Bytes String Conversion)

Fast bytes and string conversion in Go.

Usage

Follow the command to install it:

go get -u github.com/snf1k/fbsc
import (
    "fmt"

    "github.com/snf1k/fbsc"
)

func main() {
    s := "Hello World"
    b := fbsc.StringToBytes(s)
    fmt.Println(b)
    fmt.Println(fbsc.BytesToString(b))
}

Benchmark

$ GOMAXPROCS=1 go test -bench . -benchmem -benchtime=10s
BenchmarkStringToBytes           4108293              2909 ns/op           12288 B/op          1 allocs/op
BenchmarkBytesToString           4115698              3100 ns/op           12288 B/op          1 allocs/op
BenchmarkFastStringToBytes      1000000000               1.211 ns/op           0 B/op          0 allocs/op
BenchmarkFastBytesToString      1000000000               1.552 ns/op           0 B/op          0 allocs/op

License

Unlicense

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

Convert []byte to string.

Example
package main

import (
	"fmt"

	"github.com/snf1k/fbsc"
)

func main() {
	b := []byte{72, 101, 108, 108, 111}
	fmt.Println(fbsc.BytesToString(b))
}
Output:

Hello

func StringToBytes

func StringToBytes(s string) []byte

Convert string to bytes.

Example
package main

import (
	"fmt"

	"github.com/snf1k/fbsc"
)

func main() {
	s := "World"
	fmt.Println(fbsc.StringToBytes(s))
}
Output:

[87 111 114 108 100]

Types

This section is empty.

Jump to

Keyboard shortcuts

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