Skip to content

Instantly share code, notes, and snippets.

View totoleo's full-sized avatar
🎯
Focusing

LEo totoleo

🎯
Focusing
View GitHub Profile
@totoleo
totoleo / cache.go
Created September 9, 2022 14:03
localcache
package localcache
import "context"
type Cache[K comparable, T any] interface {
MGet(ctx context.Context, ids []K) ([]T, error)
}
type Storage[K comparable, T any] interface {
Load(ctx context.Context, ids []K) (map[K][]byte, error)
@totoleo
totoleo / slice_test.go
Created August 5, 2020 03:50
slice 复制
package utils
import "testing"
// BenchmarkSliceCopy 对比 slice 通过 loop 和 copy 进行复制的性能
func BenchmarkSliceCopy(b *testing.B) {
const length = 256
type foo struct {
val int
}
@totoleo
totoleo / slice_test.go
Last active June 29, 2020 13:36
slice chunk
goos: darwin
goarch: amd64
pkg: perf
BenchmarkBulk
BenchmarkBulk/re
BenchmarkBulk/re-4 15252195 67.9 ns/op 48 B/op 1 allocs/op
BenchmarkBulk/slow
BenchmarkBulk/slow-4 224365 5269 ns/op 12352 B/op 29 allocs/op
PASS
@totoleo
totoleo / map_test.go
Created June 24, 2020 11:53
测试 map 的 assign 性能
goos: darwin
goarch: amd64
pkg: perf
BenchmarkMapAssign
BenchmarkMapAssign/struct{}
BenchmarkMapAssign/struct{}-4 342277 3384 ns/op 1658 B/op 7 allocs/op
BenchmarkMapAssign/struct{}#01
BenchmarkMapAssign/struct{}#01-4 176937 6258 ns/op 3071 B/op 17 allocs/op
BenchmarkMapAssign/bool
BenchmarkMapAssign/bool-4 377792 3118 ns/op 3109 B/op 2 allocs/op
@totoleo
totoleo / str_test.go
Last active June 19, 2020 11:41
split 与 index 的性能对比
BenchmarkSubStr/split
BenchmarkSubStr/split-4 11353098 106 ns/op 32 B/op 1 allocs/op
BenchmarkSubStr/index
BenchmarkSubStr/index-4 187964112 6.37 ns/op 0 B/op 0 allocs/op
func BenchmarkFormat(b *testing.B) {
b.Run("appendFormat", func(b *testing.B) {
b.ReportAllocs()
var specIdStr []byte
var l int = 10
for i := 0; i < b.N; i++ {
val1 := rand.Int63()
val2 := rand.Int63()
val3 := rand.Int63()
#!/bin/bash --login
REMOTE_PROJECT_PATH=$1
REMOTE_GO_PATH=$2
SVC_NAME=$3
PORT=$4
EXEC_FILE=${REMOTE_PROJECT_PATH}/output/${SVC_NAME}
package ciphers
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/base64"
"testing"
)
@totoleo
totoleo / slice_2.go
Created February 14, 2019 10:20
a pitfall of slice
package main
import (
"fmt"
)
func main() {
//case 1
a := []int{}
a = append(a, 1)
@totoleo
totoleo / slice.go
Last active February 13, 2019 02:30
a Pitfall of slice in golang
package main
import (
"fmt"
"strings"
"unsafe"
)
func main() {
s := make([]int, 10, 20)