src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

store_test.go (1111B)


      1 package store
      2 
      3 import (
      4 	"os"
      5 	"testing"
      6 	"time"
      7 
      8 	"code.dwrz.net/src/pkg/dqs/diet"
      9 	"code.dwrz.net/src/pkg/dqs/entry"
     10 )
     11 
     12 func BenchmarkGetAllEntries(b *testing.B) {
     13 	b.StopTimer()
     14 
     15 	temp, err := os.MkdirTemp(os.TempDir(), "dqs")
     16 	if err != nil {
     17 		b.Errorf("failed to setup temp dir: %v", err)
     18 		return
     19 	}
     20 
     21 	s, err := Open(temp)
     22 	if err != nil {
     23 		b.Errorf("failed to open store: %v", err)
     24 		return
     25 	}
     26 
     27 	var start = time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC)
     28 	var end = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
     29 
     30 	for t := start; t.Before(end); t = t.AddDate(0, 0, 1) {
     31 		if err := s.UpdateEntry(&entry.Entry{
     32 			Categories: diet.Vegetarian.Template(),
     33 			Date:       t,
     34 			Diet:       diet.Vegetarian,
     35 		}); err != nil {
     36 			b.Errorf("failed to create entry: %v", err)
     37 			return
     38 		}
     39 	}
     40 
     41 	b.ResetTimer()
     42 
     43 	b.StartTimer()
     44 	for i := 0; i < b.N; i++ {
     45 		if _, err := s.GetAllEntries(); err != nil {
     46 			b.Errorf("failed to get all entries: %v", err)
     47 			return
     48 		}
     49 	}
     50 	b.StopTimer()
     51 
     52 	// if err := os.RemoveAll(temp); err != nil {
     53 	// 	b.Errorf("failed to remove %s directory: %v", temp, err)
     54 	// 	return
     55 	// }
     56 }