<commit_before>package main

import (
	"io"
	"io/ioutil"
	"strings"
)
import (
	"os"
	"os/exec"
)

func main() {
	before, err := ioutil.TempFile("", "benchcmp-git")
	if err != nil {
		panic(err)
	}
	defer before.Close()
	defer os.Remove(before.Name())

	err = ExecBench(before)
	if err != nil {
		panic(err)
	}

	current, err := exec.Command("git", "name-rev", "--name-only", "HEAD").Output()
	if err != nil {
		panic(err)
	}

	exec.Command("git", "checkout", "HEAD~").Run()
	defer func(branch []byte) {
		b := strings.Trim(string(branch), "\n")
		c := exec.Command("git", "checkout", b)
		c.Run()
	}(current)

	after, err := ioutil.TempFile("", "benchcmp-git")
	if err != nil {
		panic(err)
	}
	defer after.Close()
	defer os.Remove(after.Name())

	err = ExecBench(after)
	if err != nil {
		panic(err)
	}

	err = ExecCmp(os.Stdout, before.Name(), after.Name())
	if err != nil {
		panic(err)
	}
}

const (
	GO = "go"
)

func ExecBench(w io.Writer, opts ...string) error {
	o := append([]string{"test", "-run=NONE", "-bench=.", "-benchmem"}, opts...)
	out, err := exec.Command(GO, o...).Output()
	if err != nil {
		return err
	}

	_, err = w.Write(out)
	if err != nil {
		return err
	}

	return nil
}

func ExecCmp(w io.Writer, before, after string, opts ...string) error {
	CMD := "benchcmp"
	o := append([]string{before, after}, opts...)
	out, err := exec.Command(CMD, o...).Output()
	if err != nil {
		return err
	}

	_, err = w.Write(out)<commit_msg>Before <=> After. And refactor.<commit_after>package main

import (
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"strings"
)

const (
	GO = "go"
)

func main() {
	before, beforeClose, err := Tempfile()
	if err != nil {
		panic(err)
	}
	defer beforeClose()

	after, afterClose, err := Tempfile()
	if err != nil {
		panic(err)
	}
	defer afterClose()

	err = ExecBench(after)
	if err != nil {
		panic(err)
	}

	current, err := exec.Command("git", "name-rev", "--name-only", "HEAD").Output()
	if err != nil {
		panic(err)
	}

	exec.Command("git", "checkout", "HEAD~").Run()
	defer func(branch []byte) {
		b := strings.Trim(string(branch), "\n")
		c := exec.Command("git", "checkout", b)
		c.Run()
	}(current)

	err = ExecBench(before)
	if err != nil {
		panic(err)
	}

	err = ExecCmp(os.Stdout, before.Name(), after.Name())
	if err != nil {
		panic(err)
	}
}

func Tempfile() (*os.File, func(), error) {
	file, err := ioutil.TempFile("", "benchcmp-git")
	if err != nil {
		return nil, nil, err
	}
	fn := func() {
		file.Close()
		os.Remove(file.Name())
	}

	return file, fn, nil
}

func ExecBench(w io.Writer, opts ...string) error {
	o := append([]string{"test", "-run=NONE", "-bench=.", "-benchmem"}, opts...)
	out, err := exec.Command(GO, o...).Output()
	if err != nil {
		return err
	}

	_, err = w.Write(out)
	if err != nil {
		return err
	}

	return nil
}

func ExecCmp(w io.Writer, before, after string, opts ...string) error {
	CMD := "benchcmp"
	o := append([]string{before, after}, opts...)
	out, err := exec.Command(CMD, o...).Output()
	if err != nil {
		return err
	}

	_, err = w.Write(out)
{'fraction_non_alphanumeric': 0.21097601051593823, 'fraction_numerical': 0.0, 'mean_word_length': 3.281293952180028, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5148188', 'n_tokens_mistral': 1261, 'n_tokens_neox': 1201, 'n_words': 299}