Skip to content

Instantly share code, notes, and snippets.

View renanbastos93's full-sized avatar
🏄‍♂️
Free times I go surfing usually

Renan Bastos renanbastos93

🏄‍♂️
Free times I go surfing usually
View GitHub Profile
@renanbastos93
renanbastos93 / main.go
Last active April 11, 2020 07:39
Using redirect middleware with GoFiber
package main
import (
"github.com/gofiber/fiber"
"github.com/gofiber/redirect"
)
func main() {
app := fiber.New()
package main
import (
"fmt"
"time"
"github.com/gen2brain/beeep"
)
func main() {
func useAppendWithoutLength() {
var arr = []int{}
for i := 0; i < size; i++ {
arr = append(arr, i)
}
}
func useAppendWithLength() {
var arr = make([]int, 0, size)
for i := 0; i < size; i++ {
arr = append(arr, i)
}
}
func notUseAppend() {
var arr = make([]int, 1, size)
for k := range arr {
arr[k] = k
}
}
package main
var size = 10000
func useAppendWithoutLength() {
var arr = []int{}
for i := 0; i < size; i++ {
arr = append(arr, i)
}
}
func BenchmarkTestWithLength(b *testing.B) {
for i := 0; i < b.N; i++ {
useAppendWithLength()
}
}
func BenchmarkTestWithoutLength(b *testing.B) {
for i := 0; i < b.N; i++ {
useAppendWithoutLength()
}
}
func BenchmarkTestNotUseAppend(b *testing.B) {
for i := 0; i < b.N; i++ {
notUseAppend()
}
}
package main
import "testing"
func BenchmarkTestWithLength(b *testing.B) {
for i := 0; i < b.N; i++ {
useAppendWithLength()
}
}