You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go/app/tests/benchmarks_test.go

334 lines
6.3 KiB

// ------------------------------------------------------------------------
// Project activething
// Active Thing (activething.com) git.activething.com/go
//
// File name packer.go
// Created by DEV
// Modified 11/01/2024
//
// Copyright 2024 activething.com
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ------------------------------------------------------------------------
package main
import (
"activething.com/go/gogo/packs"
"activething.com/go/gogo/packs/js"
j "encoding/json"
"testing"
)
/*
var s = struct {
F1Int int
F2Uint uint
F3String string
F4Binary []byte
}{
F1Int :-111,
F2Uint: 333,
F3String: "Esto es un string <quoted & scaped >",
F4Binary: []byte("dklsdjflsdjflsdkfjlsdkfjlsdkfjlsdfjdlsfjsdlf"),
}
var packer = pjson.NewPacker()
var mp = map[int]any {
3:"23434434",
1:time.Now(),
4:233,
7:[]uint16{2323,2323,2323},
}
func BenchmarkHtmlPacker(b *testing.B) {
packer := pjson.NewPacker()
for i := 0; i < b.N; i++ {
packer.Pack(s)
if packer.Error() != nil {
panic(packer.Error())
}
packer.Reset()
}
}
func BenchmarkJsonMarshal(b *testing.B) {
var d []byte
var e error
for i := 0; i < b.N; i++ {
if false {
d,e = j.Marshal(s)
fmt.Printf("Marshal %s\n",d)
} else {
d, e = j.Marshal(s)
}
if e != nil {
panic(e)
}
}
}
func BenchmarkMapPacker(b *testing.B) {
for i := 0; i < b.N; i++ {
packer.Pack(mp)
if packer.Error() != nil {
panic(packer.Error())
}
packer.Reset()
}
}
var bf []byte
func BenchmarkMapJSON(b *testing.B) {
var e error
var d []byte
for i := 0; i < b.N; i++ {
d, e = j.Marshal(mp)
if e != nil {
panic(e)
}
}
bf = d
}
var flags = "omitempty,binary,html,rfc8550"
func BenchmarkFlagsCut (b *testing.B) {
for i:=0; i< b.N; i++ {
js.Flags(0).SetWithString(flags)
}
}
func BenchmarkFlagsParams (b *testing.B) {
for i:=0; i< b.N; i++ {
js.Flags(0).SetWithNames("omitempty","binary","html","rfc8550")
}
}
*/
//var cas = []string {"a1111","b2222","c3333"}
//var cas = []int32 {1111,2222,3333}
var cas = []float64 {1111,2222,3333}
/*
func BenchmarkListPack (b *testing.B) {
s := packs.NewState()
for i:=0; i< b.N; i++ {
js.RPacker(s,cas,0)
s.Reset()
}
}
func BenchmarkListJSON (b *testing.B) {
for i:=0; i< b.N; i++ {
j.Marshal(cas)
}
}
*/
//var ma = map[int]string {1:"344343",3:"4343434",5:"frtrtrtr"}
//var ma = map[string]string {"{asd1/>":"344343","{asd2/>":"4343434","{asd41/>":"frtrtrtr"}
var mas = map[string]int {"{basd1/>":344343,"{casd2/>":4343434,"{asd41/>":67,"{ba2sd1/>":344343,"{11casd2/>":4343434,"{33asd41/>":67}
func BenchmarkMapPack (b *testing.B) {
s := packs.NewState()
for i:=0; i< b.N; i++ {
js.RPacker(s,ma,0)
s.Reset()
}
}
func BenchmarkMapJSON (b *testing.B) {
for i:=0; i< b.N; i++ {
j.Marshal(ma)
}
}
type s struct {
start int
end int
}
func BenchmarkAppend (b *testing.B) {
for i:=0; i< b.N; i++ {
data := make([]byte,0,3200)
list := make([]s,0,100)
for k,_ := range ma {
list = append(list,s{
start: len(data),
end : len(data)+len(k),
})
data = append(data,[]byte(k)...)
}
for _,v := range list {
if len(string(data[v.start:v.end])) > 100 {
panic("Errror")
}
}
data=data[:0]
}
}
type s1 struct {
cadena string
}
func BenchmarkCrate (b *testing.B) {
for i:=0; i< b.N; i++ {
data := make([]byte,0,3200)
list := make([]s1,0,100)
for k,_ := range ma {
list = append(list,s1{
cadena: k,
})
data = append(data,[]byte(k)...)
}
for _,v := range list {
if len(v.cadena) > 100 {
panic("Errror")
}
}
data=data[:0]
}
}
var ma = map[string]string {
"clave0": "valor123",
"clave1": "rojo",
"clave2": "valor456",
"clave3": "azul",
"clave4": "valor789",
"clave5": "verde",
"clave6": "valor012",
"clave7": "amarillo",
"clave8": "valor345",
"clave9": "naranja",
"clave10": "valor678",
"clave11": "morado",
"clave12": "valor901",
"clave13": "grande",
"clave14": "valor234",
"clave15": "pequeño",
"clave16": "valor567",
"clave17": "rápido",
"clave18": "valor890",
"clave19": "lento",
"clave20": "valor123",
"clave21": "rojo",
"clave22": "valor456",
"clave23": "azul",
"clave24": "valor789",
"clave25": "verde",
"clave26": "valor012",
"clave27": "amarillo",
"clave28": "valor345",
"clave29": "naranja",
"clave30": "valor678",
"clave31": "morado",
"clave32": "valor901",
"clave33": "grande",
"clave34": "valor234",
"clave35": "pequeño",
"clave36": "valor567",
"clave37": "rápido",
"clave38": "valor890",
"clave39": "lento",
"clave40": "valor123",
"clave41": "rojo",
"clave42": "valor456",
"clave43": "azul",
"clave44": "valor789",
"clave45": "verde",
"clave46": "valor012",
"clave47": "amarillo",
"clave48": "valor345",
"clave49": "naranja",
"clave50": "valor678",
"clave51": "morado",
"clave52": "valor901",
"clave53": "grande",
"clave54": "valor234",
"clave55": "pequeño",
"clave56": "valor567",
"clave57": "rápido",
"clave58": "valor890",
"clave59": "lento",
"clave60": "valor123",
"clave61": "rojo",
"clave62": "valor456",
"clave63": "azul",
"clave64": "valor789",
"clave65": "verde",
"clave66": "valor012",
"clave67": "amarillo",
"clave68": "valor345",
"clave69": "naranja",
"clave70": "valor678",
"clave71": "morado",
"clave72": "valor901",
"clave73": "grande",
"clave74": "valor234",
"clave75": "pequeño",
"clave76": "valor567",
"clave77": "rápido",
"clave78": "valor890",
"clave79": "lento",
"clave80": "valor123",
"clave81": "rojo",
"clave82": "valor456",
"clave83": "azul",
"clave84": "valor789",
"clave85": "verde",
"clave86": "valor012",
"clave87": "amarillo",
"clave88": "valor345",
"clave89": "naranja",
"clave90": "valor678",
"clave91": "morado",
"clave92": "valor901",
"clave93": "grande",
"clave94": "valor234",
"clave95": "pequeño",
"clave96": "valor567",
"clave97": "rápido",
"clave98": "valor890",
"clave99": "lento",
}

Powered by TurnKey Linux.