High-quality micro-benchmark performance test automatic generation method and device based on large language model

Through the automatic generation method of micro-benchmark performance test based on large language model, the problems of insufficient parameter optimization, insufficient unit test and insufficient context information analysis in the existing technology are solved, and high-quality and high-accuracy micro-benchmark performance test case generation is achieved. , significantly improving the comprehensiveness and accuracy of the test.

CN119440992AActive Publication Date: 2025-02-14ZHEJIANG UNIV +1

Patent Information

Application Number
CN202411528780.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2025-02-14
Estimated Expiration
2044-10-30

AI Technical Summary

Technical Problem

Existing automatic generation technologies for microbenchmark performance tests, such as the ju2jmh framework, have the inability to automatically analyze the most suitable JMH parameters, insufficient unit tests lead to limited conversion range, insufficient optimization of generated microbenchmarks, lack of context information analysis, and JMH bad Problems such as performance testing deviations caused by practice.

Method used

Using high-quality microbenchmark performance test automatic generation method based on large language model, the context information and call link of the target method are obtained through static analysis and system dependency graph construction, and the performance analysis and parameter optimization are used for large language model to generate high-quality Readable and highly accurate microbenchmark performance test cases, and the generated code is verified and fixed to ensure its accuracy and operability.

Benefits of technology

Automatic analysis and optimization of JMH parameters is realized, and the scope of application of test conversion is expanded. The generated microbenchmark test can more accurately reflect the performance characteristics of the code, avoid performance measurement errors caused by JVM optimization, and significantly improve the comprehensiveness of the test and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119440992A_ABST
    Figure CN119440992A_ABST
Patent Text Reader

Abstract

The invention discloses a high-quality micro-benchmark performance test automatic generation method and device based on a large language model, and the method comprises the steps: carrying out the analysis of a target project, and constructing a system dependence graph; analyzing a calling link of the target method by utilizing the system dependency graph, and guiding the large language model to perform performance classification according to source codes in the calling link; the performance classification result is matched with a predefined JMH parameter template; contextual information and a parameter template of a target method are integrated, and a large language model is effectively guided to generate a high-quality micro-benchmark performance test case; and analyzing the successfully generated micro-benchmark performance test code, detecting bad practices in the code by utilizing the bad practice rule base, repairing the bad practice code, and finally generating an efficient and accurate test case. The method is superior to a traditional method in the aspects of test generation accuracy, performance defect detection capability and the like, and the generated test case has remarkable advantages in the aspects of understandability and performance measurement accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of automatic generation of micro-benchmark performance tests, and in particular, relates to a method and device for automatic generation of high-quality micro-benchmark performance tests based on a large language model. Background Art

[0002] In the hierarchy of software testing, performance testing is an important part of ensuring the stability and efficient operation of the system under actual load. Microbenchmark performance testing is particularly critical, as it can deeply analyze the smallest unit of the code, helping developers to identify problems that may affect system performance at an early stage, thereby improving the overall performance and stability of the software. However, writing high-quality microbenchmark performance test cases is usually a time-consuming and complicated process. Developers not only need to have rich experience in performance tuning, but also have to spend a lot of time on manual writing and adjustment. This also means that performance testing is often overlooked in the actual development process.

[0003] To meet this challenge, the automatic generation of micro-benchmark performance test cases has emerged. This technology aims to automatically generate test cases that cover the key performance paths of the system to ensure that the performance of the code can be fully evaluated and verified. This automatically generated micro-benchmark test can significantly improve test coverage, reduce the burden on developers, and help the team discover performance bottlenecks and potential problems early, thereby greatly improving development efficiency and optimizing the overall performance of the software.

[0004] One of the most common microbenchmark performance test automatic generation technologies is ju2jmh. By building the ju2jmh framework, microbenchmark test cases can be automatically generated. The framework screens the existing JUnit test suites for cases suitable for conversion into performance benchmarks, and performs static and dynamic analysis on them to deeply understand the structure and execution logic of the code. Then, ju2jmh will convert these JUnit tests into JMH (Java Microbenchmark Harness) benchmark tests, and perform necessary optimizations and adjustments to ensure that the generated tests can effectively evaluate system performance.

[0005] As the advantages of large language models in the field of code understanding and generation become increasingly prominent, automatically generating micro-benchmark performance test cases based on large language models has become a highly promising technical method. By converting the context information of the method to be tested into prompt words and using the large language model to generate the corresponding micro-benchmark test cases, this method can generate clearer and more accurate performance test code while ensuring high test coverage.

[0006] However, although the existing ju2jmh framework has achieved the automatic conversion from JUnit tests to microbenchmark performance tests to a certain extent, it has significant deficiencies in key aspects such as parameter optimization, test case optimization, and target method context information processing. These limitations not only narrow the application scenarios of existing methods, but also have a negative impact on the accuracy of generating microbenchmark performance tests and the precision of performance evaluation. The current automatic generation methods of microbenchmark performance tests still face the following technical problems that need to be solved:

[0007] 1. Unable to automatically analyze the most suitable JMH parameters. The ju2jmh framework cannot automatically analyze and generate the most suitable JMH parameters (such as the number of measurements, warm-up time, number of threads, etc.) according to the characteristics of the target code. These parameters are crucial to the accuracy and performance evaluation of microbenchmarks, but existing methods rely on the default parameters of the JMH framework and lack automated optimization solutions, which may cause performance test results to deviate from the actual situation and make it difficult to accurately reflect the actual performance of the system.

[0008] 2. Insufficient unit tests limit the scope of conversion. The ju2jmh framework relies on existing JUnit unit tests for conversion, but in many code bases, unit test coverage is low or even completely lacking, making it impossible to automatically generate and convert large-scale microbenchmarks. In addition, even if the code base contains unit tests, these tests are usually not designed for performance evaluation and are difficult to meet the needs of microbenchmarks, thus limiting the scope of application and actual effect of the ju2jmh framework.

[0009] 3. The generated micro-benchmarks are not optimized enough. Although ju2jmh can generate micro-benchmarks, its optimization capabilities are limited and it cannot ensure that the generated test cases can effectively identify performance bottlenecks and provide accurate performance evaluations. Since the framework mainly relies on static and dynamic analysis, it cannot fully consider complex performance influencing factors such as multi-threaded scheduling and caching mechanisms. Therefore, the generated benchmarks may not truly reflect the performance of the system in complex scenarios. In addition, the lack of further optimization of the test cases may cause deviations in the test results, limiting the application of ju2jmh in high-precision performance evaluation.

[0010] 4. Lack of analysis of contextual information. The ju2jmh framework directly converts JUnit unit tests into microbenchmarks, but fails to fully consider the dependencies and contextual information in the test methods. This direct conversion method ignores the actual execution environment of the test case and its related dependencies, which may cause the generated microbenchmark to fail to accurately reflect the performance of the system in real usage scenarios. Due to the lack of comprehensive analysis of the test context, the generated microbenchmark may not be able to effectively evaluate the performance characteristics of the system under complex dependencies, thereby limiting the comprehensiveness and accuracy of the test.

[0011] 5. Performance test deviations caused by bad JMH practices. The current ju2jmh framework may not fully identify and avoid bad JMH practices when generating microbenchmarks, such as incorrect use of return values, loop accumulation, incorrect Fork configuration, etc. These problems may cause the JVM to perform unexpected optimizations, thus affecting the accuracy of the benchmark. Summary of the invention

[0012] The present invention provides a method and device for automatically generating high-quality micro-benchmark performance tests based on a large language model. By analyzing various components of a project and combining in-depth analysis of the impact on target code performance, highly readable and accurate micro-benchmark performance test cases are automatically generated.

[0013] A method for automatically generating high-quality micro-benchmark performance tests based on a large language model comprises the following steps:

[0014] (1) Perform static analysis on the target project and build a system dependency graph to identify the context information of the target method;

[0015] (2) Based on the system dependency graph, the call chain of the target method is parsed to obtain the source code of all directly and indirectly called methods in the call chain;

[0016] (3) Using the context information of the target method and the source code in the call chain, the large language model is guided to perform performance analysis, identify the code that has a significant impact on performance, and classify it according to predefined performance categories;

[0017] (4) Match the performance classification results with the predefined JMH parameter template and select the appropriate test parameter configuration;

[0018] (5) Integrate the context information, performance classification results, and test parameter configuration of the target method to generate prompt words for input into the large language model;

[0019] (6) Using the generated prompt words to guide the large language model to generate micro-benchmark performance test cases;

[0020] (7) Verify and repair the generated micro-benchmark performance test cases to ensure their accuracy and operability;

[0021] (8) Preset a rule base, which stores a series of JMH bad practice code rules, and match the micro-benchmark performance test code verified and repaired in step (7) with the rule base to detect bad practices in the test case;

[0022] (9) Using a large language model combined with the preset prompt words and repair examples corresponding to the bad practice categories, we implement repairs on the bad practice codes detected in the test cases and verify the repaired micro-benchmarks again to ensure their accuracy and operability.

[0023] The specific process of step (1) is:

[0024] (1-1) Use a static parser to read all source code files of the target project for structural analysis. On this basis, generate the corresponding abstract syntax tree AST, which effectively represents the structure of the code, including elements such as classes, methods, and variables; Next, extract all classes and methods defined in the project from the abstract syntax tree AST, record the name, location, and methods of each class, and record the signature and class of each method.

[0025] (1-2) Analyze the dependencies between classes, identify the relationship between parent classes and child classes by checking the inheritance relationship and implemented interfaces between classes, and build the inheritance hierarchy of classes. During the analysis process, the system extracts the method call relationship, searches for method call nodes in the AST, identifies the call relationship between methods, and records other methods called within each method, including methods in the same class, methods in parent classes, implemented interface methods, and methods in external libraries. This process generates a complete call chain that shows the relationship between the target method and other methods. At the same time, the system records the construction order of classes and methods to ensure that the initialization order of classes and the calling order of methods in the project are understood.

[0026] (1-3) Integrate the identified classes and methods and their dependencies to generate a system dependency graph, where the nodes represent classes and methods, and the edges represent the dependencies between them.

[0027] (1-4) Traverse the system dependency graph constructed in (1-3) and analyze the context information of the target method, including the class construction order, method call hierarchy, inheritance relationship, and interface implementation. To reduce code interference irrelevant to the target method, the system deletes unrelated AST nodes, and the remaining AST nodes are re-parsed into source code fragments.

[0028] The specific process of step (2) is as follows:

[0029] (2-1) Through the system dependency graph constructed in step (1), identify all call nodes directly connected to the target method; these call nodes correspond to the methods directly called by the target method during its implementation process.

[0030] (2-2) Analyze the call nodes in step (2-1) to extract their related call relationships and form a complete call chain. During this process, the system will recursively analyze each call node to identify other methods called by it, including methods in the same class, methods in parent classes, implemented interface methods, and methods in external libraries. For each called method, the system will further trace its call chain and obtain all directly and indirectly dependent methods to ensure the integrity and accuracy of the call chain.

[0031] (2-3) Extract the implementation code corresponding to all call nodes related to the target method from the source code based on the call link.

[0032] The specific process of step (3) is as follows:

[0033] The source code in the call chain obtained in step (2) is input into the large language model to deeply analyze the performance characteristics of these codes during execution; during the analysis process, the large language model identifies the code snippets that have a significant impact on performance based on the context information of the call chain, including possible performance bottlenecks, memory usage, and I / O operations. Subsequently, the identified code snippets are classified according to predefined performance categories, such as: CPU intensive, I / O intensive, and memory intensive.

[0034] The specific process of step (4) is as follows:

[0035] According to the performance category identified in step (3), the corresponding predefined JMH parameter template is extracted; different performance categories correspond to different parameter templates, which set the optimal parameter combination and configuration according to the performance characteristics of the code. For example, for CPU-intensive code, the system will use a predefined template containing threads and forks parameters to evaluate CPU performance in multi-threaded and multi-process scenarios; for I / O-intensive code, the system uses a template containing warmup-Iterations and measurement-Iterations parameters to ensure that I / O operations are tested in a stable state.

[0036] The specific process of step (5) is as follows:

[0037] The target method context information obtained by analyzing step (1) is combined with the JMH parameter template matched in step (4) to construct a prompt word; the prompt word contains the context information of the target method, the performance classification result and the corresponding test parameter configuration, so as to ensure that the large language model can accurately understand the operating environment and performance requirements of the method when generating micro-benchmark performance test code, thereby improving the pertinence and effectiveness of the generated test code.

[0038] The specific process of step (6) is as follows:

[0039] The constructed prompt words are input into the large language model to guide it to generate micro-benchmark performance test code based on the context information of the target method, the call chain source code and the relevant test parameter configuration. In this way, it is ensured that the generated test cases can effectively reflect the performance characteristics of the target method and contain suitable test parameters for accurate performance evaluation in the subsequent verification and optimization stages.

[0040] The specific process of step (7) is as follows:

[0041] First, a preliminary syntax check is performed on the generated test cases to ensure that the code complies with the grammatical specifications. After passing the syntax check, the test cases are compiled and tested to verify that the code can be successfully compiled without errors. After successful compilation, the test cases are executed to detect whether there are errors or exceptions during operation. For test cases that fail the verification, the repair phase will be entered, with priority given to solving syntax, compilation or runtime errors. During the repair process, heuristic methods are used for automatic repair, or error information is fed back to the large language model to further adjust the code. Through multiple iterative corrections, the generated micro-benchmark performance test cases are ensured to run stably and accurately evaluate the performance of the target method.

[0042] The specific process of step (8) is as follows:

[0043] The system pre-builds a rule base that covers bad practices in different code patterns, such as ignoring return values, loop accumulation, incorrect fork configuration, etc., and defines the detection standards corresponding to bad practices. Subsequently, the system scans and parses the test cases, analyzes the code structure and logic of the test cases, and matches them with the bad practice entries in the rule base to identify the bad practice characteristics and categories in the test cases.

[0044] The specific process of step (9) is as follows:

[0045] Based on the identified bad practice types, the system combines the JMH benchmark code with the preset bad practice prompt words and repair examples. Through this combination, the system generates a repair request for a specific JMH bad practice and inputs it into the large language model to guide the model to generate the corresponding correction code. After generating the repair code, the system verifies the improved micro-benchmark code to ensure that it meets the best practice standards and is runnable.

[0046] A high-quality micro-benchmark performance test automatic generation device based on a large language model includes a memory and one or more processors, wherein the memory stores executable code and a micro-benchmark performance test bad practice rule library, and when the one or more processors execute the executable code, they are used to implement the above-mentioned high-quality micro-benchmark performance test automatic generation method.

[0047] Compared with the prior art, the present invention has the following beneficial effects:

[0048] 1. The present invention can automatically generate the most suitable JMH parameters according to the characteristics of the target code through the deep analysis capability of the large language model, such as the number of measurements, warm-up time, number of threads, etc. This parameter optimization mechanism based on code context overcomes the limitation of relying on default parameters in existing methods, significantly improves the accuracy of micro-benchmark test results, and can more realistically reflect the performance of the target code.

[0049] 2. The present invention no longer relies on the existing unit tests and their coverage in the project, but generates high-quality micro-benchmark performance test cases through a large language model. Even if the unit tests in the project are insufficient or completely missing, the present invention can still automatically analyze the code structure and generate micro-benchmark test cases that meet the performance evaluation requirements, thereby expanding the scope of application of test conversion and overcoming the limitations of existing methods when unit test coverage is insufficient.

[0050] 3. The present invention comprehensively analyzes the context information, dependencies and execution environment of the target code, and the generated micro-benchmark performance test cases can more accurately reflect the performance characteristics of the code. With the introduction of a large language model, the present invention overcomes the shortcomings of existing methods in context information analysis, ensures that the generated micro-benchmark performance test can comprehensively evaluate the performance of the system under complex dependencies, and significantly improves the comprehensiveness and accuracy of the test.

[0051] 4. The present invention ensures the accuracy of benchmark testing by effectively improving the bad practices in generating test codes for large models, avoids performance measurement errors caused by JVM optimization, further improves the reliability of test results, provides developers with more instructive performance evaluation basis, and promotes efficient and accurate code optimization and performance tuning. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 This is a flow chart of a method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to an embodiment of the present invention.

[0053] Figure 2 The figure is a flow chart of parsing context information of a target method in an embodiment of the present invention.

[0054] Figure 3 This is a flow chart of target method call link analysis in an embodiment of the present invention.

[0055] Figure 4 It is a flow chart of performance classification and JMH parameter template matching in an embodiment of the present invention.

[0056] Figure 5 A flow chart for generating and optimizing micro-benchmark performance test cases in an embodiment of the present invention.

[0057] Figure 6 4 is a flowchart of bad practice detection and repair in an embodiment of the present invention. DETAILED DESCRIPTION

[0058] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be pointed out that the embodiments described below are intended to facilitate the understanding of the present invention and do not have any limiting effect on the present invention.

[0059] like Figure 1 As shown, a method for automatically generating high-quality micro-benchmark performance tests based on a large language model includes the following steps:

[0060] S10: Analyze the context information of the target method. The specific process is as follows: Figure 2 shown.

[0061] S101: Analyze the system dependency graph and extract context information.

[0062] The present invention first constructs a system dependency graph to identify the context information of the target method. The system dependency graph shows the relationship between classes in the project, dependencies, method calls and other information. The present invention uses a static parser to comprehensively analyze the class, inheritance relationship, implemented interface, related member variables and internal classes where the target method is located. This step is intended to fully display the execution environment of the target method and ensure that all relevant context information that may affect the execution of the target method can be fully identified and extracted. Through this analysis, the information provided to the large language model will be more accurate, thereby helping it understand the overall execution logic of the target method.

[0063] S102: Filter irrelevant context information.

[0064] In order to improve the accuracy and effectiveness of generating micro-benchmark performance tests, the present invention introduces a specific context filtering mechanism to remove context information irrelevant to the execution of the target method. The implementation steps of the filtering mechanism include: first, analyzing the dependencies of the target method, identifying and deleting classes or methods irrelevant to the test purpose; second, further statically parsing the calls involving polymorphism to ensure that only the context information that has a direct impact on the execution of the target method is retained.

[0065] S103: Generate simplified context information.

[0066] After filtering the context information, the present invention integrates and simplifies the relevant context information obtained through analysis to generate prompt words for input into the large language model. The generated prompt words will cover the source code of the target method, information about its class and dependent classes, information about dependent methods, and other necessary context information. This step ensures that the information in the prompt words is both concise and comprehensive, aiming to help the large language model accurately call the target method when generating test cases, thereby improving the generation quality of micro-benchmark performance tests.

[0067] S20: Parse the method call chain and extract the method source code in the call chain. The specific process is as follows: Figure 3 shown.

[0068] S201: Generate a method call graph (Call Graph, CG).

[0069] The present invention first performs static analysis on the project based on the system dependency graph obtained by parsing in step S10 to generate a call graph of the target method. The call graph shows the call relationship of all methods directly or indirectly called by the target method, including internal method calls and external library method calls. The key step in generating the call graph is to parse the method calls in the source code and track the definition location of each called method to accurately determine its dependency relationship.

[0070] S202: Extract the call link of the target method.

[0071] By analyzing the generated call graph, the complete call chain of the target method is identified and extracted. The call chain shows all the methods that the target method depends on during execution and their calling order. This step helps to identify related methods that may affect the performance of the target method and ensure that the complete call path is accurately recorded.

[0072] S203: Obtain the source code of each method in the call link.

[0073] After determining the call link of the target method, the present invention extracts the complete source code of all methods on the call link from the source code through a static parser. The code of each called method is precisely located at a specific location in the source code file. The extracted source code includes the main implementation of each method, ensuring that sufficient context information is provided for subsequent performance analysis.

[0074] S204: Integrate the method source code in the call link with the context of the target method.

[0075] In order to provide a comprehensive analysis context, the present invention integrates the source code of each method in the extracted call chain with the source code of the target method. The integrated context contains not only the implementation details of the target method, but also all the method codes on its call chain. This context construction ensures that the performance analysis model can make accurate classification judgments based on the complete code environment.

[0076] S30: Performance classification of code snippets. The specific process is as follows: Figure 4 shown.

[0077] S301: Perform performance classification based on the call link context.

[0078] The present invention inputs the source code context of the target method and its related methods in the call chain extracted by static analysis into the conversational large language model, guiding the model to automatically analyze and determine the performance category of the target code. The context information of the call chain includes the source code of the target method and the source code of the related methods in the call chain, ensuring that the large language model can comprehensively analyze all performance characteristics that may be involved in the execution process of the target code.

[0079] During the analysis process, the large language model identifies the target code and the performance characteristics involved in its call chain based on context information, and classifies the code snippets according to performance characteristics. Performance categories include but are not limited to:

[0080] CPU-intensive code snippets: contain complex calculations, algorithms, or loop operations.

[0081] I / O intensive code snippets: involving I / O operations such as file operations and network communications.

[0082] Memory-intensive code snippets: those involving frequent memory allocation, deallocation, or operations to manage large data structures.

[0083] This step aims to provide guidance for the subsequent generated tests and ensure that the corresponding test parameter template is selected for the code snippet of each type of performance characteristics to optimize the accuracy and efficiency of the microbenchmark test.

[0084] S302: Optimizing the JMH parameter template based on performance classification.

[0085] The present invention provides optimized JMH parameter templates for large language models for code snippets of different performance categories. The parameter items in these templates are designed for different performance operations, ensuring that the model can generate more targeted micro-benchmark test codes and reasonably select JMH parameters and their optimal values.

[0086] For I / O-intensive code snippets, the template preferentially includes the warmup-Iterations and measurement-Iterations parameters to ensure that I / O operations are tested in a stable state and to obtain accurate performance data.

[0087] For CPU-intensive code snippets, the template includes threads and forks parameters to evaluate CPU performance in multi-threaded and multi-process cases.

[0088] For memory-intensive code snippets, the template adjusts the warmup-Iterations parameter to ensure that interference during the warmup phase is eliminated and accurately reflect the actual performance of memory management operations.

[0089] S303: Integrate the classification results and the parameter template and generate prompt words.

[0090] When generating micro-benchmark code, the present invention integrates the performance classification information of the code snippet and the corresponding JMH parameter template into a prompt word, which is input into the conversational large language model. The prompt word not only includes the source code information of the target method and its context, but also combines JMH parameters suitable for different performance characteristics.

[0091] S40: Combine the target code context generated by S10 and the JMH parameter template generated by S30 to prompt the large language model to generate test cases. The specific process is as follows: Figure 5 shown.

[0092] S401: Generate prompt words based on the target method context and parameter template.

[0093] In this step, the present invention first combines the target method context generated in step S10 with the performance classification information generated in step S30 and its corresponding JMH parameter template as a prompt word for generating a micro-benchmark performance test. The prompt word includes the target method context information and the JMH parameter template corresponding to the target method performance category, which clearly defines the parameters that need to be adjusted during the test and their specific configuration.

[0094] S402: Generate micro-benchmark performance test code.

[0095] The generated prompt words are input into the conversational large language model, and the model generates a response including an initial micro-benchmark performance test case based on the input context information and parameter template. The test case includes a micro-benchmark test code applicable to the target method, and the parameter configuration is based on the classification result and the corresponding template in S302.

[0096] S403: Test case optimization and verification.

[0097] The present invention performs syntax checking, compilation and execution testing on the generated micro-benchmark performance test code. If errors are found during the test, the system will automatically repair and optimize them through heuristic methods or with the help of a large language model. After multiple iterations and corrections, a verified micro-benchmark performance test case is generated.

[0098] S50: Bad practice detection and repair, the specific process is as follows Figure 6 shown.

[0099] S501: Detect bad practices in JMH benchmark code.

[0100] The present invention constructs a rule base containing a variety of JMH bad practices, which covers bad practice descriptions and corresponding detection standards for different code patterns. Subsequently, the system parses the generated JMH benchmark code and identifies code features related to bad practices by comparing the entries in the rule base. If no bad practice is identified, the current micro-benchmark performance test case is deemed to be the micro-benchmark performance test case that has finally passed verification; if a bad practice is identified, step S502 is entered.

[0101] S502: Fix bad practices.

[0102] After detecting bad practices in the JMH benchmark code, the method of the present invention integrates predefined prompt words and repair examples with the JMH benchmark code. Specifically, the method generates repair requests for the identified bad practice categories and inputs the requests into the large language model to guide it to generate corresponding correction codes. After the micro-benchmark performance test code is generated, it returns to step S403 for optimization and verification.

[0103] Based on the same inventive principle, an embodiment of the present invention also provides a high-quality micro-benchmark performance test automatic generation device based on a large language model, including a memory and one or more processors, wherein the memory stores executable code and a micro-benchmark performance test bad practice rule library, and when one or more processors execute the executable code, it is used to implement the high-quality micro-benchmark performance test automatic generation method of the above embodiment.

[0104] The embodiments described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above are only specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for automatically generating high-quality micro-benchmark performance tests based on a large language model, characterized in that: The following steps are involved: (1) Perform static analysis on the target project and build a system dependency graph to identify the context information of the target method; (2) Based on the system dependency graph, the call chain of the target method is parsed to obtain the source code of all directly and indirectly called methods in the call chain; (3) Using the context information of the target method and the source code in the call chain, the large language model is guided to perform performance analysis, identify the code that has a significant impact on performance, and classify it according to predefined performance categories; (4) Match the performance classification results with the predefined JMH parameter template and select the appropriate test parameter configuration; (5) Integrate the context information, performance classification results, and test parameter configuration of the target method to generate prompt words for input into the large language model; (6) Using the generated prompt words to guide the large language model to generate micro-benchmark performance test cases; (7) Verify and repair the generated micro-benchmark performance test cases to ensure their accuracy and operability; (8) Preset a rule base, which stores a series of JMH bad practice code rules, and match the micro-benchmark performance test code verified and repaired in step (7) with the rule base to detect bad practices in the test case; (9) Using a large language model combined with the preset prompt words and repair examples corresponding to the bad practice categories, we implement repairs on the bad practice codes detected in the test cases and verify the repaired micro-benchmarks again to ensure their accuracy and operability.

2. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (1) is: (1-1) Use a static parser to read all source code files of the target project, and on this basis, generate the corresponding abstract syntax tree AST to effectively represent the structure of the code; Next, extract all classes and methods defined in the project from the abstract syntax tree AST; (1-2) Analyze the dependencies between classes, identify the relationship between parent classes and child classes by checking the inheritance relationships and implemented interfaces between classes, and build the inheritance hierarchy of classes; (1-3) Integrate the identified classes and methods and their dependencies to generate a system dependency graph, where nodes represent classes and methods and edges represent the dependencies between them; (1-4) Traverse the system dependency graph constructed in (1-3) and analyze the context information of the target method, including the class construction order, method call hierarchy, inheritance relationship and interface implementation.

3. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (2) is as follows: (2-1) identifying all call nodes directly connected to the target method through the system dependency graph constructed in step (1); these call nodes correspond to the methods directly called by the target method during its implementation; (2-2) Analyze the call node in step (2-1) to extract its related call relationship and form a complete call link; (2-3) Extract the implementation code corresponding to all call nodes related to the target method from the source code based on the call link.

4. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (3) is as follows: The source code in the call chain obtained in step (2) is input into the large language model so that it can deeply analyze the performance characteristics of these codes during execution; during the analysis process, the large language model identifies the code snippets that have a significant impact on performance based on the context information of the call chain, and then classifies the identified code snippets according to predefined performance categories.

5. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (4) is as follows: According to the performance category identified in step (3), the pre-defined corresponding JMH parameter template is extracted; different performance categories correspond to different parameter templates, and these templates set the optimal parameter combination and configuration according to the performance characteristics of the code.

6. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (5) is as follows: The target method context information analyzed in step (1) is combined with the JMH parameter template matched in step (4) to construct a prompt word; the prompt word includes the context information of the target method, the performance classification result and the corresponding test parameter configuration.

7. The method for automatically generating high-quality micro-benchmark performance tests based on a large language model according to claim 1, characterized in that: The specific process of step (7) is as follows: First, perform a preliminary syntax check on the generated test cases to ensure that the code complies with the syntax specifications; after passing the syntax check, perform a compilation test on the test cases to verify that the code can be successfully compiled without errors; After successful compilation, execute the test case to detect whether there are any errors or exceptions during the operation; For test cases that fail verification, they will enter the repair phase, with priority given to solving syntax, compilation, or runtime errors; repair In the process, heuristic methods are used for automatic repair, or error information is fed back to the large language model to further adjust the code; Through multiple iterative corrections, the generated micro-benchmark performance test cases are ensured to run stably and accurately evaluate the performance of the target method.

8. A high-quality micro-benchmark performance test automatic generation device based on a large language model, characterized in that: It comprises a memory and one or more processors, wherein the memory stores executable code and a micro-benchmark performance test bad practice rule base, and when the one or more processors execute the executable code, they are used to implement the high-quality micro-benchmark performance test automatic generation method described in any one of claims 1-7.

Citation Information

Patent Citations

  • Interface testing method and related equipment

    CN118331888A

  • Method and device for automatically generating unit test based on thinking chain prompt

    CN118503125A

  • Python test case generation method based on combination of big language model and type information

    CN118733432A

  • Facilitating updates to data pipelines using modularly-generated platform-agnostic data pipeline portions systems and methods

    US20240319976A1

Cited By

  • Task process repairing method and device, equipment, medium and product

    CN120086054A

  • A task flow repairing method, device, equipment, medium and product applied to a low-code platform

    CN120086054B

  • JavaScript context awareness test generation method and system based on large model

    CN120872845A