mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-21 12:26:02 +03:00
[DEV] Added benchmark example
This commit is contained in:
parent
5d9d262a26
commit
54e4ceb31f
7
array/main.go
Normal file
7
array/main.go
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
// Array is fixed length, also data stored in a
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
46
benchmark/main.go
Normal file
46
benchmark/main.go
Normal file
@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Human interface {
|
||||
Speak()
|
||||
}
|
||||
|
||||
type Australia struct {
|
||||
}
|
||||
|
||||
func (h *Australia) Speak() {
|
||||
fmt.Println("I am Australia")
|
||||
}
|
||||
|
||||
func InterfacePresentation(vs ...interface{}) {
|
||||
t := time.Now()
|
||||
for _, v := range vs {
|
||||
b := time.Since(t)
|
||||
fmt.Println("Before Checking", b)
|
||||
m, ok := interface{}(v).(Human)
|
||||
a := time.Since(t)
|
||||
fmt.Println("After Checking", a)
|
||||
if ok {
|
||||
m.Speak()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func Presentation(human ...Human) {
|
||||
for _, h := range human {
|
||||
h.Speak()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var persons []interface{} = make([]interface{}, 100)
|
||||
for i := 0; i <= 100; i++ {
|
||||
persons = append(persons, &Australia{})
|
||||
}
|
||||
InterfacePresentation(persons...)
|
||||
}
|
21
shadow/main.go
Normal file
21
shadow/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func f() string {
|
||||
return "test"
|
||||
}
|
||||
|
||||
func init() {
|
||||
fmt.Println(f())
|
||||
}
|
||||
|
||||
var g = "g"
|
||||
|
||||
func main() {
|
||||
s := "hello world"
|
||||
p := &s
|
||||
*p = "H2"
|
||||
fmt.Println(s, s[0], len([]byte(s)))
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user