Created
April 8, 2018 06:18
-
-
Save tulik/0dd9c932e2c2102991af9ec6c9793f07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
bench(if_func_1) | |
bench(if_func_2) | |
bench(if_func_3) | |
} | |
func bench(f func(int)) { | |
var i int = 0 | |
start := time.Now(); | |
for i = 2147483647; -2147483648 != i; i-- { | |
f(i) | |
} | |
elapsed := time.Since(start) | |
fmt.Println(elapsed) | |
} | |
func if_func_1(i int) { | |
if 0 == i { | |
return | |
} | |
if 1 == i { | |
return | |
} | |
if 2 == i { | |
return | |
} | |
if 3 == i { | |
return | |
} | |
return | |
} | |
func if_func_2(i int) { | |
if 0 == i { | |
return | |
} else if 1 == i { | |
return | |
} else if 2 == i { | |
return | |
} else if 3 == i { | |
return | |
} | |
return | |
} | |
func if_func_3(i int) { | |
if 0 == i || 1 == i || 2 == i || 3 == i { | |
return | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment