mirror of
https://github.com/golang/go
synced 2024-11-22 10:44:41 -07:00
8f84328fdc
GOARCH=amd64 benchmarks src/pkg/runtime benchmark old ns/op new ns/op delta BenchmarkConvT2ESmall 10 10 +1.00% BenchmarkConvT2EUintptr 9 0 -92.07% BenchmarkConvT2EBig 74 74 -0.27% BenchmarkConvT2I 27 26 -3.62% BenchmarkConvI2E 4 4 -7.05% BenchmarkConvI2I 20 19 -2.99% test/bench/go1 benchmark old ns/op new ns/op delta BenchmarkBinaryTree17 5930908000 5937260000 +0.11% BenchmarkFannkuch11 3927057000 3933556000 +0.17% BenchmarkGobDecode 21998090 21870620 -0.58% BenchmarkGobEncode 12725310 12734480 +0.07% BenchmarkGzip 567617600 567892800 +0.05% BenchmarkGunzip 178284100 178706900 +0.24% BenchmarkJSONEncode 87693550 86794300 -1.03% BenchmarkJSONDecode 314212600 324115000 +3.15% BenchmarkMandelbrot200 7016640 7073766 +0.81% BenchmarkParse 7852100 7892085 +0.51% BenchmarkRevcomp 1285663000 1286147000 +0.04% BenchmarkTemplate 566823800 567606200 +0.14% I'm not entirely sure why the JSON* numbers have changed, but eyeballing the profile suggests that it could be spending less and more time in runtime.{new,old}stack, so it could simply be stack-split boundary noise. R=rsc, dave, bsiegert, dsymonds CC=golang-dev https://golang.org/cl/6280049
115 lines
2.2 KiB
Go
115 lines
2.2 KiB
Go
// run
|
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test conversion from non-interface types to the empty interface.
|
|
|
|
package main
|
|
|
|
var (
|
|
z = struct{}{}
|
|
p = &z
|
|
pp = &p
|
|
u16 = uint16(1)
|
|
u32 = uint32(2)
|
|
u64 = uint64(3)
|
|
u128 = [2]uint64{4, 5}
|
|
f32 = float32(6)
|
|
f64 = float64(7)
|
|
c128 = complex128(8 + 9i)
|
|
s = "10"
|
|
b = []byte("11")
|
|
m = map[int]int{12: 13}
|
|
c = make(chan int, 14)
|
|
)
|
|
|
|
var (
|
|
iz interface{} = z
|
|
ip interface{} = p
|
|
ipp interface{} = pp
|
|
iu16 interface{} = u16
|
|
iu32 interface{} = u32
|
|
iu64 interface{} = u64
|
|
iu128 interface{} = u128
|
|
if32 interface{} = f32
|
|
if64 interface{} = f64
|
|
ic128 interface{} = c128
|
|
is interface{} = s
|
|
ib interface{} = b
|
|
im interface{} = m
|
|
ic interface{} = c
|
|
)
|
|
|
|
func second(a ...interface{}) interface{} {
|
|
return a[1]
|
|
}
|
|
|
|
func main() {
|
|
// Test equality. There are no tests for b and m, as slices and
|
|
// maps are not comparable by ==.
|
|
if z != iz {
|
|
panic("z != iz")
|
|
}
|
|
if p != ip {
|
|
panic("p != ip")
|
|
}
|
|
if pp != ipp {
|
|
panic("pp != ipp")
|
|
}
|
|
if u16 != iu16 {
|
|
panic("u16 != iu16")
|
|
}
|
|
if u32 != iu32 {
|
|
panic("u32 != iu32")
|
|
}
|
|
if u64 != iu64 {
|
|
panic("u64 != iu64")
|
|
}
|
|
if u128 != iu128 {
|
|
panic("u128 != iu128")
|
|
}
|
|
if f32 != if32 {
|
|
panic("f32 != if32")
|
|
}
|
|
if f64 != if64 {
|
|
panic("f64 != if64")
|
|
}
|
|
if c128 != ic128 {
|
|
panic("c128 != ic128")
|
|
}
|
|
if s != is {
|
|
panic("s != is")
|
|
}
|
|
if c != ic {
|
|
panic("c != ic")
|
|
}
|
|
|
|
// Test that non-interface types can be used as ...interface{} arguments.
|
|
if got := second(z, p, pp, u16, u32, u64, u128, f32, f64, c128, s, b, m, c); got != ip {
|
|
println("second: got", got, "want", ip)
|
|
panic("fail")
|
|
}
|
|
|
|
// Test that non-interface types can be sent on a chan interface{}.
|
|
const n = 100
|
|
uc := make(chan interface{})
|
|
go func() {
|
|
for i := 0; i < n; i++ {
|
|
select {
|
|
case uc <- nil:
|
|
case uc <- u32:
|
|
case uc <- u64:
|
|
case uc <- u128:
|
|
}
|
|
}
|
|
}()
|
|
for i := 0; i < n; i++ {
|
|
if got := <-uc; got != nil && got != u32 && got != u64 && got != u128 {
|
|
println("recv: i", i, "got", got)
|
|
panic("fail")
|
|
}
|
|
}
|
|
}
|