<commit_before>package proto

import (
	"testing"

	"github.com/xiaonanln/vacuum/uuid"
)

type testMsg struct {
	ID        string
	F1        float64
	F2        int
	ListField []interface{}
	MapField  map[string]interface{}
}

func BenchmarkJSONMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &JSONMsgPacker{})
}

func BenchmarkMessagePackMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &MessagePackMsgPacker{})
}

func BenchmarkGobMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &GobMsgPacker{})
}

func benchmarkMsgPacker(b *testing.B, packer MsgPacker) {
	msg := testMsg{
		ID:        "abc",
		F1:        0.123124234,
		ListField: []interface{}{1, 2, 3, "abc", "def"},
		MapField:  map[string]interface{}{},
	}
	for i := 0; i < 100; i++ {
		msg.MapField[uuid.GenUUID()] = uuid.GenUUID()
	}

	for i := 0; i < b.N; i++ {

		buf := make([]byte, 0, 100)
		buf, _ = packer.PackMsg(msg, buf)

		//log.Printf("MsgPack: %v => %s(%d), error %v", msg, string(buf), len(buf), err)
		var restoreMsg RegisterVacuumServerMsg
		_ = packer.UnpackMsg(buf, &restoreMsg)
		//log.Printf("MsgPack: %s => %v, error %v", string(buf), msg, err)
		if msg.ID != restoreMsg.ID {
			b.Fail()
		}
	}
}<commit_msg>proto<commit_after>package proto

import (
	"testing"

	"github.com/xiaonanln/vacuum/uuid"
)

type testMsg struct {
	ID        string
	F1        float64
	F2        int
	ListField []interface{}
	MapField  map[string]interface{}
}

func BenchmarkJSONMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &JSONMsgPacker{})
}

func BenchmarkMessagePackMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &MessagePackMsgPacker{})
}

func BenchmarkGobMsgPacker(b *testing.B) {
	benchmarkMsgPacker(b, &GobMsgPacker{})
}

func benchmarkMsgPacker(b *testing.B, packer MsgPacker) {
	b.Logf("Testing MsgPacker %T ...", packer)
	msg := testMsg{
		ID:        "abc",
		F1:        0.123124234,
		ListField: []interface{}{1, 2, 3, "abc", "def"},
		MapField:  map[string]interface{}{},
	}
	for i := 0; i < 100; i++ {
		msg.MapField[uuid.GenUUID()] = uuid.GenUUID()
	}

	for i := 0; i < b.N; i++ {

		buf := make([]byte, 0, 100)
		buf, _ = packer.PackMsg(msg, buf)

		//log.Printf("MsgPack: %v => %s(%d), error %v", msg, string(buf), len(buf), err)
		var restoreMsg RegisterVacuumServerMsg
		_ = packer.UnpackMsg(buf, &restoreMsg)
		//log.Printf("MsgPack: %s => %v, error %v", string(buf), msg, err)
		if msg.ID != restoreMsg.ID {
			b.Fail()
		}
	}
}
{'fraction_non_alphanumeric': 0.17232808616404308, 'fraction_numerical': 0.02236951118475559, 'mean_word_length': 3.782178217821782, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2054250', 'n_tokens_mistral': 1050, 'n_tokens_neox': 974, 'n_words': 202}