<commit_before>package main

import (
	"fmt"
	"log"
	"strconv"
	"time"

	"github.com/continusec/verifiabledatastructures"
	"github.com/continusec/verifiabledatastructures/pb"
)

func loadLog(acc *verifiabledatastructures.Account) {
	vlog := acc.VerifiableLog("test")

	count := 20000

	start := time.Now()
	var err error
	var lastLeaf verifiabledatastructures.LogUpdatePromise
	for i := 0; i < count; i++ {
		lastLeaf, err = vlog.Add(&pb.LeafData{LeafInput: []byte("v" + strconv.Itoa(i))})
		if err != nil {
			log.Fatal(err)
		}
		if i%10000 == 0 {
			log.Println(i)
			end := time.Now()
			fmt.Println("Objects per second:", float64(i)/end.Sub(start).Seconds())
		}
	}
	end := time.Now()
	fmt.Println("Objects per second:", float64(count)/end.Sub(start).Seconds())
	treeHead, err := lastLeaf.Wait()
	if err != nil {
		log.Fatal(err)
	}

	end = time.Now()

	fmt.Println("Actual objects per second:", float64(count)/end.Sub(start).Seconds())
	fmt.Println("Tree head:", treeHead)
}

func loadMap(acc *verifiabledatastructures.Account) {
	vmap := acc.VerifiableMap("maptest")

	count := 1000000

	start := time.Now()
	var err error
	for i := 0; i < count; i++ {
		_, err = vmap.Set([]byte("k"+strconv.Itoa(i)), &pb.LeafData{LeafInput: []byte("v" + strconv.Itoa(i))})
		if err != nil {
			log.Fatal(err)
		}
		if i%1000 == 0 {
			log.Println(i)
			end := time.Now()
			fmt.Println("Objects per second:", float64(i)/end.Sub(start).Seconds())
		}
	}
	end := time.Now()

	treeHead, err := vmap.TreeHead(0)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Objects per second:", float64(count)/end.Sub(start).Seconds())
	fmt.Println("Tree head:", treeHead)
}

func main() {
	db := &verifiabledatastructures.BoltBackedService{Path: "/Users/aeijdenberg/Documents/continusec/vdsdemo/data"}
	//db := &verifiabledatastructures.TransientHashMapStorage{}
	acc := (&verifiabledatastructures.Client{Service: (&verifiabledatastructures.LocalService{
		AccessPolicy: &verifiabledatastructures.AnythingGoesOracle{},
		Mutator: (&verifiabledatastructures.BatchMutator{
			Writer:     db,
			BatchSize:  1000,
			BufferSize: 100000,
			Timeout:    time.Millisecond * 10,
		}).MustCreate(),
		//Mutator:      &api.InstantMutator{Writer: db},
		Reader: db,
	}).MustCreate()}).Account("0", "")
	loadLog(acc)
}
<commit_msg>Update test command to use contexts<commit_after>package main

import (
	"context"
	"fmt"
	"log"
	"strconv"
	"time"

	"github.com/continusec/verifiabledatastructures"
	"github.com/continusec/verifiabledatastructures/pb"
)

func loadLog(acc *verifiabledatastructures.Account) {
	vlog := acc.VerifiableLog("test")

	count := 100000

	ctx := context.Background()

	start := time.Now()
	var err error
	var lastLeaf verifiabledatastructures.LogUpdatePromise
	for i := 0; i < count; i++ {
		lastLeaf, err = vlog.Add(ctx, &pb.LeafData{LeafInput: []byte("v" + strconv.Itoa(i))})
		if err != nil {
			log.Fatal(err)
		}
		if i%10000 == 0 {
			log.Println(i)
			end := time.Now()
			fmt.Println("Objects per second:", float64(i)/end.Sub(start).Seconds())
		}
	}
	end := time.Now()
	fmt.Println("Objects per second:", float64(count)/end.Sub(start).Seconds())
	treeHead, err := lastLeaf.Wait(ctx)
	if err != nil {
		log.Fatal(err)
	}

	end = time.Now()

	fmt.Println("Actual objects per second:", float64(count)/end.Sub(start).Seconds())
	fmt.Println("Tree head:", treeHead)
}

func loadMap(acc *verifiabledatastructures.Account) {
	vmap := acc.VerifiableMap("maptest")

	count := 1000000

	ctx := context.Background()

	start := time.Now()
	var err error
	for i := 0; i < count; i++ {
		_, err = vmap.Set(ctx, []byte("k"+strconv.Itoa(i)), &pb.LeafData{LeafInput: []byte("v" + strconv.Itoa(i))})
		if err != nil {
			log.Fatal(err)
		}
		if i%1000 == 0 {
			log.Println(i)
			end := time.Now()
			fmt.Println("Objects per second:", float64(i)/end.Sub(start).Seconds())
		}
	}
	end := time.Now()

	treeHead, err := vmap.TreeHead(ctx, 0)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Objects per second:", float64(count)/end.Sub(start).Seconds())
	fmt.Println("Tree head:", treeHead)
}

func main() {
	//db := &verifiabledatastructures.BoltBackedService{Path: "/Users/aeijdenberg/Documents/continusec/vdsdemo/data"}
	db := &verifiabledatastructures.TransientHashMapStorage{}
	acc := (&verifiabledatastructures.Client{Service: (&verifiabledatastructures.LocalService{
		AccessPolicy: &verifiabledatastructures.AnythingGoesOracle{},
		Mutator: (&verifiabledatastructures.BatchMutator{
			Writer:     db,
			BatchSize:  1000,
			BufferSize: 100000,
			Timeout:    time.Millisecond * 10,
		}).MustCreate(),
		//Mutator: &verifiabledatastructures.InstantMutator{Writer: db},
		Reader: db,
	}).MustCreate()}).Account("0", "")
	loadLog(acc)
}

{'fraction_non_alphanumeric': 0.17280033840947548, 'fraction_numerical': 0.020939086294416244, 'mean_word_length': 4.4607390300230945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178046', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1767, 'n_words': 325}