Skip to content

Instantly share code, notes, and snippets.

@swvitaliy

swvitaliy/go.mod Secret

Created September 24, 2023 16:06
Show Gist options
  • Save swvitaliy/00582a7eaf8a986363683d66090a90d5 to your computer and use it in GitHub Desktop.
Save swvitaliy/00582a7eaf8a986363683d66090a90d5 to your computer and use it in GitHub Desktop.
readInf
module readInf
go 1.21
require (
github.com/mfonda/simhash v0.0.0-20151007195837-79f94a1100d6 // indirect
golang.org/x/text v0.13.0 // indirect
)
package main
import (
"crypto/rand"
"fmt"
"github.com/mfonda/simhash"
"sync/atomic"
"time"
)
type Node struct {
Val []byte
Next *Node
}
func randBlocks(num int, bufSize int) *Node {
var head *Node = nil
cur := head
for i := 0; i < num; i++ {
b := make([]byte, bufSize)
n, err := rand.Read(b)
if err != nil {
panic(err)
}
if n == 0 {
break
}
newNode := &Node{
Val: b,
Next: nil,
}
if cur == nil {
cur = newNode
head = cur
} else {
cur.Next = newNode
cur = cur.Next
}
}
cur.Next = head
return head
}
func main() {
blocks := randBlocks(8*10, 128*1024) // total: 10MB
var c int64 = 0
for i := 0; i < 10; i++ {
go func() {
cur := blocks
for {
featureSet := simhash.NewWordFeatureSet(cur.Val)
simhash.Simhash(featureSet)
atomic.AddInt64(&c, 1)
cur = cur.Next
}
}()
}
var p int64 = 0
t := time.Now()
for {
time.Sleep(2 * time.Second)
fmt.Printf("%.2f op/s\n", float64(c-p)/time.Since(t).Seconds())
p = c
t = time.Now()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment