MCPcopy Create free account
hub / github.com/M4THYOU/TokenDagger / CodePerformanceBenchmark

Class CodePerformanceBenchmark

tests/code_performance_benchmark.py:64–590  ·  view source on GitHub ↗

Performance benchmark specifically for code tokenization.

Source from the content-addressed store, hash-verified

62
63
64class CodePerformanceBenchmark:
65 """Performance benchmark specifically for code tokenization."""
66
67 def __init__(self, warmup_runs: int = 3, benchmark_runs: int = 25, tokenizer_type: str = "llama"):
68 self.repo_root = Path(__file__).parent.parent
69 self.warmup_runs = warmup_runs
70 self.benchmark_runs = benchmark_runs
71 self.tokenizer_type = tokenizer_type.lower()
72 self.results: List[CodeBenchmarkResult] = []
73
74 # Validate tokenizer type
75 if self.tokenizer_type not in ["llama", "mistral"]:
76 raise ValueError(f"Invalid tokenizer type: {tokenizer_type}. Must be 'llama' or 'mistral'")
77
78 # Code file extensions to test
79 self.code_extensions = {
80 '.py': 'Python',
81 '.cpp': 'C++',
82 '.c': 'C',
83 '.h': 'C Header',
84 '.hpp': 'C++ Header',
85 '.js': 'JavaScript',
86 '.ts': 'TypeScript',
87 '.java': 'Java',
88 '.rs': 'Rust',
89 '.go': 'Go',
90 '.rb': 'Ruby',
91 '.php': 'PHP',
92 '.cs': 'C#',
93 '.swift': 'Swift',
94 '.kt': 'Kotlin',
95 '.scala': 'Scala',
96 '.sh': 'Shell',
97 '.bat': 'Batch',
98 '.ps1': 'PowerShell',
99 '.sql': 'SQL',
100 '.json': 'JSON',
101 '.xml': 'XML',
102 '.yaml': 'YAML',
103 '.yml': 'YAML',
104 '.md': 'Markdown',
105 '.txt': 'Text',
106 '.makefile': 'Makefile',
107 '.cmake': 'CMake'
108 }
109
110 def setup_tokenizers(self):
111 """Initialize both tokenizers."""
112 print(f"Setting up tokenizers with {self.tokenizer_type.title()} configuration...")
113
114 # Load configuration based on tokenizer type
115 if self.tokenizer_type == "llama":
116 pattern, vocab, special_tokens = self.load_llama_config()
117 elif self.tokenizer_type == "mistral":
118 pattern, vocab, special_tokens = self.load_mistral_config()
119 else:
120 raise ValueError(f"Unsupported tokenizer type: {self.tokenizer_type}")
121

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected