<commit_before>// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Test STW latency and mark throughput on large, heterogeneous heaps.
package main

import (
	"flag"
	"fmt"
	"os"
	"time"

	"github.com/aclements/go-gcbench/gcbench"
	"github.com/aclements/go-gcbench/gcbench/heapgen"
)

var sink1, sink2 interface{}

var (
	flagDuration = flag.Duration("benchtime", 20*time.Second, "steady state duration")
	flagMB       = flag.Int("mb", 1<<10, "retain `x` MB of heap")
	flagHeap     = flag.String("heap", "AST", "heap `shape`; either \"AST\" or \"deBruijn2\"")
)

var heapMaker func() interface{}

func main() {
	flag.Parse()
	if flag.NArg() > 0 {
		flag.Usage()
		os.Exit(2)
	}
	switch *flagHeap {
	case "AST":
		heapMaker = heapgen.MakeAST
	case "deBruijn2":
		heapMaker = func() interface{} {
			// About 1MB per graph.
			return heapgen.MakeDeBruijn2(16)
		}
	default:
		fmt.Fprintf(os.Stderr, "unknown -heap shape %q\n", *flagHeap)
		flag.Usage()
		os.Exit(2)
	}

	gcbench.NewBenchmark("LargeHeap", benchMain).Config("mb", *flagMB).Config("heap", *flagHeap).Run()
}

func benchMain() {
	m := heapgen.Measure(heapMaker)
	println(m.BytesRetained, "bytes per graph")
	sink1 = heapgen.Generate(m.Gen, m.BytesRetained, *flagMB<<20)

	// On my laptop for 1.5 and 1.6, this takes another ~10
	// seconds to reach steady state.
	time.AfterFunc(*flagDuration, func() { os.Exit(0) })
	for {
		sink2 = m.Gen()
	}
}<commit_msg>gcbench: use FlagBytes for largeheap<commit_after>// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Test STW latency and mark throughput on large, heterogeneous heaps.
package main

import (
	"flag"
	"fmt"
	"os"
	"time"

	"github.com/aclements/go-gcbench/gcbench"
	"github.com/aclements/go-gcbench/gcbench/heapgen"
)

var sink1, sink2 interface{}

var (
	flagDuration = flag.Duration("benchtime", 20*time.Second, "steady state duration")
	flagRetain   = gcbench.FlagBytes("retain", gcbench.GB, "retain `x` bytes of heap")
	flagHeap     = flag.String("heap", "AST", "heap `shape`; either \"AST\" or \"deBruijn2\"")
)

var heapMaker func() interface{}

func main() {
	flag.Parse()
	if flag.NArg() > 0 {
		flag.Usage()
		os.Exit(2)
	}
	switch *flagHeap {
	case "AST":
		heapMaker = heapgen.MakeAST
	case "deBruijn2":
		heapMaker = func() interface{} {
			// About 1MB per graph.
			return heapgen.MakeDeBruijn2(16)
		}
	default:
		fmt.Fprintf(os.Stderr, "unknown -heap shape %q\n", *flagHeap)
		flag.Usage()
		os.Exit(2)
	}

	gcbench.NewBenchmark("LargeHeap", benchMain).Config("retain", *flagRetain).Config("heap", *flagHeap).Run()
}

func benchMain() {
	m := heapgen.Measure(heapMaker)
	println(m.BytesRetained, "bytes per graph")
	sink1 = heapgen.Generate(m.Gen, m.BytesRetained, int(*flagRetain))

	// On my laptop for 1.5 and 1.6, this takes another ~10
	// seconds to reach steady state.
	time.AfterFunc(*flagDuration, func() { os.Exit(0) })
	for {
		sink2 = m.Gen()
	}
}
{'fraction_non_alphanumeric': 0.1527109400064164, 'fraction_numerical': 0.01828681424446583, 'mean_word_length': 3.871875, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, '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': '6928900', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1150, 'n_words': 306}