fsbc

package module
v0.0.0-...-0f2834e Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: Unlicense Imports: 1 Imported by: 0

README

fsbc (Fast String Bytes Conversion)

Convert strings and bytes with high performance in Go.

Usage

Use the following command to get it.

go get -u codeberg.org/galaxy/fsbc
package main

import (
    "fmt"

    "codeberg.org/galaxy/fsbc"
)

func main() {
    bytes := fsbc.StringToBytes("Hello World!")
    fmt.Println(bytes) // convert string to bytes

    str := fsbc.BytesToString([]byte{72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33}) // convert bytes to string
    fmt.Println(str) // output is "Hello World!"
}

Benchmark

$ GOMAXPROCS=1 go test -bench . -benchmem -benchtime=10s
BenchmarkStringToBytes              2317           4742097 ns/op        16777216 B/op          1 allocs/op
BenchmarkBytesToString              2316           4735531 ns/op        16777216 B/op          1 allocs/op
BenchmarkFastStringToBytes      1000000000               0.9639 ns/op          0 B/op          0 allocs/op
BenchmarkFastBytesToString      1000000000               1.442 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
Example
package main

import (
	"fmt"

	"codeberg.org/galaxy/fsbc"
)

func main() {
	bytes := []byte{72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33}
	str := fsbc.BytesToString(bytes)
	fmt.Println(str)
}
Output:

Hello World!

func StringToBytes

func StringToBytes(s string) []byte
Example
package main

import (
	"fmt"

	"codeberg.org/galaxy/fsbc"
)

func main() {
	str := "Hello World!"
	bytes := fsbc.StringToBytes(str)
	fmt.Println(bytes)
}
Output:

[72 101 108 108 111 32 87 111 114 108 100 33]

Types

This section is empty.

Jump to

Keyboard shortcuts

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