Skip to content

Instantly share code, notes, and snippets.

Avatar
✍️
Writing

Teiva Harsanyi teivah

✍️
Writing
View GitHub Profile
View ilp.go
package main
import (
"testing"
)
const n = 1_000_000
func loop1(s [2]int64) [2]int64 {
for i := 0; i < n; i++ {
View sum.go
package main
import (
"sync"
"testing"
)
const m = 1_000_000
type S struct {
View compute-sum.go
package main
import (
"math/rand"
"strconv"
"testing"
)
var res int64
View goroutines_leak.go
func TestFoo(t *testing.T) {
defer checkGoroutinesLeak(t)()
foo()
}
func checkGoroutinesLeak(t *testing.T) func() {
before := runtime.NumGoroutine()
return func() {
after := runtime.NumGoroutine()
if after > before {
View bench.go
const size = 512
var result int64
func Benchmark8Size(b *testing.B) {
const arraySize = 8
s := make([][arraySize]int64, size)
var r int64
b.ResetTimer()
View BenchmarkStructurePaddingStruct.go
type PaddedStruct struct {
n int
_ CacheLinePad
}
type CacheLinePad struct {
_ [CacheLinePadSize]byte
}
const CacheLinePadSize = 64
View BenchmarkStructurePadding.go
func BenchmarkStructurePadding(b *testing.B) {
structA := PaddedStruct{}
structB := SimpleStruct{}
wg := sync.WaitGroup{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg.Add(2)
go func() {
for j := 0; j < M; j++ {
View BenchmarkStructureFalseSharing.go
type SimpleStruct struct {
n int
}
func BenchmarkStructureFalseSharing(b *testing.B) {
structA := SimpleStruct{}
structB := SimpleStruct{}
wg := sync.WaitGroup{}
b.ResetTimer()
View BenchmarkMatrixReversedCombinationPerBlock.go
func BenchmarkMatrixReversedCombinationPerBlock(b *testing.B) {
matrixA := createMatrix(matrixLength)
matrixB := createMatrix(matrixLength)
blockSize := 8
for n := 0; n < b.N; n++ {
for i := 0; i < matrixLength; i += blockSize {
for j := 0; j < matrixLength; j += blockSize {
for ii := i; ii < i+blockSize; ii++ {
for jj := j; jj < j+blockSize; jj++ {
View BenchmarkMatrixReversedCombination.go
func BenchmarkMatrixReversedCombination(b *testing.B) {
matrixA := createMatrix(matrixLength)
matrixB := createMatrix(matrixLength)
for n := 0; n < b.N; n++ {
for i := 0; i < matrixLength; i++ {
for j := 0; j < matrixLength; j++ {
matrixA[i][j] = matrixA[i][j] + matrixB[j][i]
}
}