Exploring the Impact of the Output Format on the Evaluation of Large Language Models for Code TranslationFull Paper
Code translation between programming languages is a long-existing and critical task in software engineering, facilitating the modernization of legacy systems, ensuring cross-platform compatibility, and enhancing software performance. With the recent advances in large language models (LLMs) and their applications to code translation, there is an increasing need for comprehensive evaluation of these models. In this study, we empirically analyze the generated outputs of eleven popular instruct-tuned LLMs with parameters ranging from 1B up to 46.7B on 3,820 translation pairs across five languages including C, C++, Go, Java, and Python. In our analysis, we found that between 26.4% and 73.7% of code translations produced by our evaluated LLMs necessitate post-processing. This is because these translations often include a mix of code, quotes, and text, rather than being purely source code. Overlooking the output format of these models can inadvertently lead to underestimation of their true performance. This is particularly evident when evaluating them with execution-based metrics such as Computational Accuracy (CA). Our research demonstrates a strategic combination of prompt engineering and regular expression usage that can effectively extract the source code from the model generation output. Results show that our method can help eleven selected models achieve an average Code Extraction Success Rate (CSR) of 92.73%. We believe our findings shed light and motivate future research in conducting more reliable benchmarks of LLMs for code translation.