v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/runtime2/mlocal_test.go (about)

     1  package runtime2
     2  
     3  import "testing"
     4  
     5  func TestSetGet(t *testing.T) {
     6  	var mls = NewMLocal[int]()
     7  	for i := 0; i < 100000; i++ {
     8  		mls.Set(i)
     9  		if v := mls.Get(); v != i {
    10  			panic("i != v")
    11  		}
    12  	}
    13  }
    14  
    15  func BenchmarkSetGet(b *testing.B) {
    16  	mls := NewMLocal[int]()
    17  	b.RunParallel(func(p *testing.PB) {
    18  		var i int
    19  		for p.Next() {
    20  			mls.Set(i)
    21  			mls.Get()
    22  			i++
    23  		}
    24  	})
    25  }