hikan.ru/benchmarks/stuff.go

68 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package benchmarks
import (
"html/template"
"math/rand"
"strings"
"time"
)
var globalStringList = []string{"#Aiogram", "#Go", "#JS", "#Windows", "#Анонимность",
"#Апдейт", "#Ассемблер", "#Веб", "#Идеи", "#Книги", "#Музыка", "#Находки",
"#Нейросети", "#ООП", "#Осайте", "#Прога", "#Си", "#Фронтенд"}
var randGen = rand.New(rand.NewSource(time.Now().UnixNano()))
// Структура поста
type Post struct {
ID int
Author string
Title string
Body template.HTML
PostingTime string
UpdateTime string
Tags string
Lock int
}
type Posts []Post
// random 5 tags for post
func tag5() string {
return globalStringList[randGen.Intn(len(globalStringList))] + " " +
globalStringList[randGen.Intn(len(globalStringList))] + " " +
globalStringList[randGen.Intn(len(globalStringList))] + " " +
globalStringList[randGen.Intn(len(globalStringList))] + " " +
globalStringList[randGen.Intn(len(globalStringList))]
}
func generatePostsList() Posts {
var p Posts
for i := 0; i < 100; i++ {
p = append(p, GetLargePost())
}
return p
}
// generate big post
func GetLargePost() Post {
author := "admin"
title := "A Comprehensive Guide to Go Programming Language"
body := strings.Repeat("REPEAT ME", 500)
postingTime := time.Now().Format("2006-01-02 15:04:05")
updateTime := postingTime
tags := tag5()
lock := 0
return Post{
ID: 1,
Author: author,
Title: title,
Body: template.HTML(body),
PostingTime: postingTime,
UpdateTime: updateTime,
Tags: tags,
Lock: lock,
}
}