Code snippet extraction iteration use method and system based on parallelization

The running time of code fragments is optimized through the K nearest neighbor method and the Black-winged Kitchen optimization algorithm, and the number of parallel threads is adjusted in combination with the differentiated creative search algorithm, which solves the problems of slow and low iteration of code fragment extraction and iteration in the existing technology, and achieves efficient Code snippet iteration and optimization.

CN119201131AInactive Publication Date: 2024-12-27JINHUA BADA GRP CO LTD +2
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411586489.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-08
Publication Date
2024-12-27
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The prior art has slow speed during the extraction and iteration of code fragments and fails to effectively optimize the running efficiency and time complexity of code fragments, making it difficult to determine the portability of code fragments and the number of parallel threads.

Method used

By obtaining the calling time ratio of code snippet functions, use the K nearest neighbor method to classify hotspot functions, and combine the time complexity of the objective function and the Black-winged Bourne optimization algorithm to optimize the code snippet running time; detect similarity through string feature vectors, and remove duplicate codes Snippets; Finally, adjust the number of parallel threads based on differentiated creative search algorithms to optimize the running efficiency of code snippets.

Benefits of technology

It realizes efficient extraction and iteration of code snippets, improves running efficiency and time complexity, simplifies the adjustment of parallel thread counts of code snippets, and improves the portability of code snippets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201131A_ABST
    Figure CN119201131A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of electronic digital data processing, and discloses a parallelization-based code snippet extraction iteration use method and system. The method comprises the following steps: firstly, obtaining a code snippet function, obtaining a code snippet hotspot function by using a K-nearest neighbor method, and recording the code snippet hotspot function as a first code extraction iteration condition; calculating the time complexity of the target function in the code snippets to obtain processed code snippets, and optimizing the running time of the processed code snippets in the program by using a black-wing optimization algorithm to obtain optimized code snippets; performing similarity detection on the optimized code snippets, screening to obtain similarity code snippets, and recording the similarity code snippets as second code extraction iteration conditions; and finally, combining the first code extraction iteration condition and the second code extraction iteration condition to obtain a to-be-processed code snippet, and optimizing the parallel thread count of the to-be-processed code snippet to realize code snippet extraction iteration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electronic digital data processing, and in particular to a method and system for iterative use of code fragment extraction based on parallelization. Background Art

[0002] Chinese patent CN102279750B discloses an iterative code generation method based on domain knowledge sharing, which specifically includes: firstly, developing a core generation system based on a dynamic language, wherein the core generation system includes using interfaces, developing interfaces, description documents, automated testing, and deployment kits; using the core code generation system to generate a conventional application system, wherein the conventional application system includes extracting common knowledge codes and domain data to facilitate iteration; and developing a specific domain application system based on the common knowledge codes and domain data, wherein the common knowledge codes can be extracted and iterated using the specific domain application system. This method only realizes the extraction and iteration of the code, and the code extraction speed is slow, and no attention is paid to the operating efficiency and time complexity of extracting code fragments.

[0003] The same piece of program code cannot achieve good time complexity when running on different architectures; the traditional method iteratively compiles and optimizes code snippets based on experience, but the optimal code snippet running time cannot be obtained during the iterative compilation and optimization process, resulting in difficulty in portability of code snippets and difficulty in extraction and iteration; the traditional method requires copying the code snippet each time, and it is also difficult to determine the number of parallel threads of the code snippet after copying. Summary of the invention

[0004] In view of the problems in the related art, the present invention provides a method and system for iterative use of code snippets extracted based on parallelization to overcome the above-mentioned technical problems existing in the existing related art.

[0005] In order to solve the above technical problems, the present invention is achieved through the following technical solutions: The present invention is a method for iteratively using code fragments extracted based on parallelization, comprising the following steps: S1. Obtain a code snippet function, generate a code snippet function call time proportion matrix, classify the code snippet function call time proportion matrix using a K-nearest neighbor method, obtain a code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition; S2. Use the time complexity of the objective function in the code snippet and the running time of the code snippet in the program to measure the running quality of the code snippet, and use the Black Kite optimization algorithm to optimize the running time of the code snippet in the program to obtain the optimized code snippet; S3, generating a string matrix according to the optimized code snippets, performing similarity detection on the strings in the string matrix, removing code snippets with similar features, obtaining similar code snippets, and recording the similar code snippets as the second code extraction iteration condition; S4. Combining the first code extraction iteration condition and the second code extraction iteration condition, obtain the code snippet to be processed, run the code snippet to be processed, and adjust the number of parallel threads, optimize the code snippet running efficiency based on the differentiated creative search algorithm, and realize code snippet extraction iteration.

[0006] The invention first obtains the code snippet function, calculates the call time ratio of the code snippet function, records the call time ratio as the condition for selecting the hot function, uses the K nearest neighbor method to classify the code snippet function call time ratio matrix, obtains the code snippet hot function, and records the code snippet hot function as the first code extraction iteration condition; secondly, the target function time complexity in the code snippet and the running time of the code snippet in the program are used to measure the running quality of the code snippet, the target function time complexity is obtained through the target function call relationship, the black kite optimization algorithm is used to optimize the running time of the code snippet in the program to obtain the optimal running time, and the optimal position is obtained by changing the hunting and migration position of the black kite. The method has strong evolutionary ability, fast search speed and strong optimization ability; then the string in the code snippet is converted into a string feature vector, and the similarity of the string feature vector is calculated to determine whether the string is repeated, and the repeated string is deleted to obtain a similarity code snippet, and the similarity code snippet is recorded as the second code extraction iteration condition; then the first code extraction iteration condition is added to the second code extraction iteration condition to complete the code snippet extraction, and finally the number of parallel threads of the code snippet to be processed is adjusted based on the differentiated creative search algorithm to optimize the running efficiency of the code snippet and realize code snippet iteration. The algorithm is mainly based on the black kite attack strategy and migration behavior to improve decision-making efficiency, and has the efficient ability to solve complex optimization problems.

[0007] Preferably, the S1 comprises the following steps: S11, obtain the code snippet function, calculate the call time proportion of the code snippet function to obtain the code snippet function call time proportion set, recorded as ,in Indicates The feature dimension of the code snippet function call time proportion in the code snippet function call time proportion set is set to , generate the code snippet function call time proportion matrix as follows, , in, Indicates the code snippet function call time ratio matrix The feature dimension is The percentage of time that the code snippet function is called; Set a comparison code snippet function set, calculate the call time ratio of the comparison code snippet function in the comparison code snippet function set in the comparison code snippet, and obtain the comparison code snippet function time ratio set; select a column in the code snippet function call time ratio matrix as the first code snippet function call time ratio set ,in Indicates the code snippet function call time ratio matrix The feature dimension is The percentage of time that the code snippet function is called; S12, set the similarity threshold to , select the function time proportion of the compared code snippet set that is greater than The code snippet function call time percentage is recorded as the second code snippet function call time percentage set; according to the similarity of the sample data of the first code snippet function call time percentage set and the second code snippet function call time percentage set, the code snippet function call time percentage corresponding to the minimum similarity value is recorded as the adjacent point to obtain the adjacent point set ,in Indicates a nearby point; set up Indicates the representative coefficient of the adjacent point in the adjacent point set, represents the representative coefficient of the code snippet function call time proportion in the first code snippet function call time proportion set, represents the weight, represents a classification function and when the data sample corresponding to the minimum similarity value is in the first code snippet function call time proportion set, the classification function takes 1, otherwise the classification function takes 0; calculate the weight of the adjacent points in the adjacent point set , the calculation formula is as follows,

[0008] in, represents the weight of the adjacent points in the adjacent point set, Indicates the first The representative coefficient of the adjacent points is ; Calculate the weight values ​​of the neighboring points in the neighboring point set, select the maximum weight value of the neighboring points in the neighboring point set, obtain the sample data of the first code snippet function call time proportion set of the neighboring points corresponding to the maximum weight value of the neighboring points in the neighboring point set, record it as the code snippet function call time proportion to be classified, compose a code snippet function call time proportion set according to the code snippet function call time proportion to be classified, find the code snippet function corresponding to the code snippet function call time proportion in the code snippet function call time proportion set, record it as a code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition.

[0009] The invention obtains code snippet functions, calculates the call time percentage of the code snippet functions, uses the ones with high call time percentage as the conditions for selecting hot functions, and then uses the K-nearest neighbor method to obtain the representative coefficient of the call time percentage of the code snippet functions, classifies the set of call time percentages of the code snippet functions, obtains the code snippet hotspot functions, and records the code snippet hotspot functions as the first code extraction iteration condition.

[0010] Preferably, S2 comprises the following steps: S21. Set the code snippet to include objective functions, and the objective function set is ,in Indicates objective function, select an objective function from the objective function set As the initial function, generate a directed graph based on the calling relationship of the initial function Stored in an adjacency linked list, where Represents a call relationship set; Set the calling relationship set of the initial function to include atomic functions, and the set of atomic functions is ,in Indicates Atomic functions, the time complexity calculation process of the atomic functions in the atomic function set is as follows: S211, set the loop body set to ,in Indicates loop variables, When the number of changes of the loop variables in the loop body set is an arbitrary constant, the time complexity of the loop variables in the loop body set is ; When the number of changes of the loop variables in the loop body set is recorded as an indefinite term , the time complexity of the loop variables in the loop body set is ; When the number of changes of the loop variables in the loop body set is recorded as an indefinite term And the change of the loop variables in the loop body set is doubled. At this time, the time complexity of the loop variables in the loop body set is ; Complete the judgment of the loop variables in the loop body set; S212, set the loop body nested set to ,in Indicates The loop body nesting relationship, when the loop variable in the loop body set and The loop body nesting relationship in the loop body nesting set is satisfied, and the loop variables in the loop body set is the outer loop, where and Respectively represent and loop variables, then the time complexity of the loop variables in the loop body set is ; Set a basic statement loop body execution statement set, select the most frequently executed statement in the basic statement loop body execution statement set, and the time complexity of the most frequently executed statement in the basic statement loop body execution statement set ; The atomic functions in the atomic function set include A basic statement loop executes a statement set to obtain the The most frequently executed statement in the basic statement loop execution statement set, then the time complexity of the atomic function in the atomic function set is ; S22, after obtaining the time complexity of the atomic functions in the atomic function set, the atomic functions in the atomic function set are backtracked according to S211 and S212 to obtain the time complexity of the initial function, the time complexity of the target function in the code fragment is calculated, and the time complexity set of the target function in the code fragment is generated. The time complexity threshold is set to , discard the code snippet where the objective function time complexity is greater than The target function is obtained to obtain the processed code fragment; S23, setting the target function set of the processed code fragment to ,in Indicates The objective function has a characteristic dimension of , generating the objective function matrix of the code snippet as follows, , in, Indicates The feature dimension is The objective function of Use the Black Kite optimization algorithm to optimize the running time of the code snippet in the program and set the fitness function ,in Indicates the interruption time of the service. Indicates the execution time of the code snippet, Indicates the error time. The specific process is as follows: S231, setting the objective function in the objective function matrix of the code fragment to represent the position of the black-winged kite, the number of individuals in the black-winged kite population is , the characteristic dimension of black kite is , No. Only feature dimension The calculation formula for the initial position of the black-winged kite is as follows:

[0011] in, Indicates Only feature dimension The initial position of the black-winged kite, Indicates A black kite Dimensional upper bound, Indicates A black kite Dimensional lower bound, represents a random number and ; S232, when attacking prey, the black-winged kite constantly changes its position, constantly optimizes the running time of the code snippet in the program, and sets the black-winged kite The position at the iteration is , Black-winged Kite The position at the iteration is , the maximum number of iterations is , the judgment coefficient of black-winged kite attacking prey is , represents a random number and , , Expressed as a constant, the calculation formula is as follows, , , When the black kite When the code snippet is in the program, the running time of the optimized code snippet is completed. Iterations; S233, Black-winged kites introduce black-winged kite leaders during migration, and set the fitness of the black-winged kite population to , when the current fitness Greater than When the black-winged kite leader leads the black-winged kite population to migrate; set the migration process The position at the iteration is , during migration The position at the iteration is , the black kite migration process coefficient is , the Cauchy distribution function is , the leader position of the Black Winged Kite is , represents the running time of the code snippet in the program, and the calculation formula is as follows, , , The black-winged kite continuously searches for the minimum fitness during migration and sets the current number of iterations. When the current number of iterations is greater than the maximum number of iterations, the iteration is stopped, and the running time of the code snippet in the program is optimized to obtain the optimized code snippet.

[0012] The invention measures the running quality of a code snippet by using the time complexity of the target function in the code snippet and the running time of the code snippet in the program, obtains the time complexity of the target function through the target function call relationship, uses the black kite optimization algorithm to optimize the running time of the code snippet in the program to obtain the optimal running time, and obtains the optimal position through the changes in the hunting and migration positions of the black kite. The algorithm has strong evolutionary ability, fast search speed and strong optimization ability.

[0013] Preferably, S3 comprises the following steps: S31, setting the optimized code snippet to include string, denoted as ,in Indicates strings, the feature dimension of the string is , get the string matrix as follows, , in, Indicates The feature dimension is String; The strings in the string matrix are converted into string feature vectors, two string feature vectors in the string matrix are taken, and the two string feature vectors in the string matrix are normalized to obtain a normalized vector and , the similarity calculation formula is as follows,

[0014] in, Represents the similarity of strings in the string matrix; S32, calculate the vector cosine value of the two string feature vectors in the string matrix, and set the similarity threshold to , the vector cosine value threshold is , when the vector cosine value of the two string feature vectors in the string matrix is ​​greater than or equal to And the similarity of the strings in the string matrix is ​​greater than or equal to When , the strings in the string matrix are the same, and the strings in the same string matrix are deleted; when the vector cosine value of the two string feature vectors in the string matrix is ​​less than And the similarity of the strings in the string matrix is ​​less than When , the strings in the string matrix are not the same, and the strings in the string matrix are retained; a similarity code fragment is obtained, and the similarity code fragment is recorded as the second code extraction iteration condition.

[0015] The invention converts the character string in the code fragment into a character string feature vector, calculates the similarity of the character string feature vector, determines whether the character string is repeated, deletes the repeated character string, obtains a similarity code fragment, records the similarity code fragment as the second code extraction iteration condition, and uses the vector cosine value of the character string feature vector to obtain a more accurate result.

[0016] Preferably, S4 comprises the following steps: S41, the first code extraction iteration condition is the code snippet hotspot function, the second code extraction iteration condition is the similarity code snippet, the code snippet hotspot function is added to the similarity code snippet, the code snippet extraction is completed, and the code snippet set to be processed is obtained, which is recorded as ,in Indicates The code snippets to be processed are set to have a feature dimension of , generate a matrix of code snippets to be processed as follows, , in, Indicates The feature dimension is The code snippet to be processed; Use the differentiated creative search algorithm to optimize the number of parallel threads, optimize the running efficiency of the code snippets to be processed in the code snippet matrix to be processed, and set the code snippets to be processed in the code snippet matrix The number of solutions to the problem is , the problem solution dimension is , the code snippet matrix to be processed is recorded as the problem solution matrix, and the individual generation formula in the problem solution matrix is ​​as follows,

[0017] in, represents a random number and , Represents the problem solution matrix Dimensional upper bound, Represents the problem solution matrix Dimensional lower bound; S42. Setting fitness function ,in Indicates storage efficiency, represents the input efficiency, represents the output efficiency; calculate the fitness of individuals in the problem solution matrix, rank them from large to small according to their fitness in the problem solution matrix, and obtain the ranking number; in the differentiated knowledge acquisition stage, set the first The differential knowledge acquisition rate of the iteration is , No. The variable of differential knowledge acquisition in the iteration is , No. The individual ranking number of the iteration is , the maximum number of iterations is , the calculation formula is as follows, , , Set the first threshold to , when The number of iterations of differential knowledge acquisition variables is less than When the problem solution matrix is ​​selected, the individuals are selected as experimental individuals. The first iteration differentiates the knowledge acquisition rate to learn, absorb and integrate new knowledge or experience, and start the process of optimizing the number of parallel threads; set the The individual position of the iteration test is , No. The individual position in the solution matrix of the iteration problem is , then The formula for calculating the individual position in the solution matrix of the iteration problem is as follows:

[0018] After the individual positions in the problem solution matrix are replaced, a new problem solution matrix is ​​obtained, and the process of optimizing the number of parallel threads is completed. Iterations; S43. In the convergent thinking stage, a team leader is introduced. The team leader position satisfies the maximum fitness function. At this time, the code fragments to be processed in the code fragment matrix to be processed have the best running efficiency. Set the The position of the iteration team leader is , select the individual positions in the new problem solution matrix respectively and , No. The iteration coefficients are , and , the maximum number of iterations is , then the calculation formula for individual position update in the new problem solution matrix is ​​as follows: , , coefficient Continuously adjust the team leader position, set the current iteration number and the second threshold , when the current number of iterations is equal to the maximum number of iterations and the position of the individual in the new problem solution matrix is ​​less than , the team leader position is obtained; otherwise, S42 and S43 are repeated until the current number of iterations is equal to the maximum number of iterations, and the individual position in the new problem solution matrix is ​​less than ; Find the value of the horizontal coordinate of the corresponding position of the team leader position in the problem solution matrix, recorded as , is the number of parallel threads. The code fragments to be processed in the code fragment matrix are The number of parallel threads running is 1, and the code snippet is iteratively used.

[0019] The invention obtains the code fragment to be processed by combining the first code extraction iteration condition and the second code extraction iteration condition, completes the code fragment extraction, adjusts the number of parallel threads for the code fragment to be processed based on the differentiated creative search algorithm, obtains the team leader position through individual continuous learning convergence, obtains the number of parallel threads, and completes the code fragment iteration. The algorithm has the efficient ability to solve complex optimization problems.

[0020] This embodiment also discloses a system for a method of iteratively using code snippets extracted based on parallelization, which specifically includes: a code snippet hotspot function acquisition module, a code snippet running quality measurement module, a similarity code snippet detection module, and a parallel thread number adjustment module; The code snippet hot function acquisition module is used to classify the code snippet function call time proportion matrix to obtain the code snippet hot function; The code snippet execution quality measurement module is used to measure the code snippet execution quality using the time complexity of the target function in the code snippet and the execution time of the code snippet in the program; The similarity code snippet detection module is used to perform similarity detection on the character strings generated by the code snippets and delete the code snippets with similar features; The parallel thread number adjustment module is used to use a differentiated creative search algorithm to adjust the parallel thread number to optimize the running efficiency of the code snippet.

[0021] The present invention has the following beneficial effects: 1. The invention obtains the code snippet function, calculates the call time percentage of the code snippet function, and then uses the K-nearest neighbor method to classify the code snippet function call time percentage set to obtain the code snippet hotspot function, and records the code snippet hotspot function as the first code extraction iteration condition.

[0022] 2. The invention measures the running quality of a code snippet by using the time complexity of the target function in the code snippet and the running time of the code snippet in the program, obtains the time complexity of the target function through the target function call relationship, and uses the Black Kite optimization algorithm to optimize the running time of the code snippet in the program to obtain the optimal running time.

[0023] 3. The invention converts the character string in the code snippet into a character string feature vector, calculates the similarity of the character string feature vector, obtains the similarity code snippet, and records the similarity code snippet as the second code extraction iteration condition; combines the first code extraction iteration condition and the second code extraction iteration condition to obtain the code snippet to be processed, adjusts the number of parallel threads for the code snippet to be processed based on the differentiated creative search algorithm, realizes the highest running efficiency of the code snippet to be processed, obtains the number of parallel threads, and completes the iteration of the code snippet.

[0024] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions of the embodiments of the invention, the drawings required for describing the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the invention. For ordinary technicians in this field, they can also obtain drawings based on these drawings without paying creative work.

[0026] Figure 1 The present invention provides a flowchart of iterative use of code snippets by a system based on a parallelized iterative use method for extracting code snippets. DETAILED DESCRIPTION

[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] In the description of the present invention, it is necessary to understand that the terms "opening", "upper", "lower", "top", "middle", "inside" and the like indicating orientation or positional relationship are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the components or elements referred to must have a specific orientation, be constructed and operate in a specific orientation, and therefore cannot be understood as limiting the invention.

[0029] This embodiment discloses a method for iterative use of code snippet extraction based on parallelization, which specifically includes the following contents: S1. Obtain a code snippet function, generate a code snippet function call time proportion matrix, classify the code snippet function call time proportion matrix using a K-nearest neighbor method, obtain a code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition; The S1 comprises the following steps: S11, obtain the code snippet function, calculate the call time proportion of the code snippet function to obtain the code snippet function call time proportion set, recorded as ,in Indicates The feature dimension of the code snippet function call time proportion in the code snippet function call time proportion set is set to , generate the code snippet function call time proportion matrix as follows, , in, Indicates the code snippet function call time ratio matrix The feature dimension is The percentage of time that the code snippet function is called; Set a comparison code snippet function set, calculate the call time proportion of the comparison code snippet function in the comparison code snippet function set in the comparison code snippet function set, and obtain the comparison code snippet function time proportion set; select a column in the code snippet function call time proportion matrix as the first code snippet function call time proportion set ,in Indicates the code snippet function call time ratio matrix The feature dimension is The percentage of time that the code snippet function is called; S12, set the similarity threshold to , select the function time proportion of the compared code snippet set that is greater than The code snippet function call time percentage is recorded as the second code snippet function call time percentage set; according to the similarity of the sample data of the first code snippet function call time percentage set and the second code snippet function call time percentage set, the code snippet function call time percentage corresponding to the minimum similarity value is recorded as the adjacent point to obtain the adjacent point set ,in Indicates a nearby point; set up Indicates the representative coefficient of the adjacent point in the adjacent point set, represents the representative coefficient of the code snippet function call time proportion in the first code snippet function call time proportion set, represents the weight, represents a classification function and when the data sample corresponding to the minimum similarity value is in the first code snippet function call time proportion set, the classification function takes 1, otherwise the classification function takes 0; calculate the weight of the adjacent points in the adjacent point set , the calculation formula is as follows,

[0030] in, represents the weight of the adjacent points in the adjacent point set, Indicates the first The representative coefficient of the adjacent points is ; Calculate and obtain weight values ​​of adjacent points in the adjacent point set, select the maximum value of the weight values ​​of adjacent points in the adjacent point set, obtain sample data of the first code snippet function call time proportion set of adjacent points corresponding to the maximum value of the weight values ​​of adjacent points in the adjacent point set, record it as the code snippet function call time proportion to be classified, form a code snippet function call time proportion set from the code snippet function call time proportion to be classified, find the code snippet function corresponding to the code snippet function call time proportion in the code snippet function call time proportion set, record it as a code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition; S2. Use the time complexity of the objective function in the code snippet and the running time of the code snippet in the program to measure the running quality of the code snippet, and use the Black Kite optimization algorithm to optimize the running time of the code snippet in the program to obtain the optimized code snippet; The S2 comprises the following steps: S21. Set the code snippet to include objective functions, and the objective function set is ,in Indicates objective function, select an objective function from the objective function set As the initial function, generate a directed graph based on the calling relationship of the initial function Stored in an adjacency linked list, where Represents a call relationship set; Set the calling relationship set of the initial function to include atomic functions, and the set of atomic functions is ,in Indicates Atomic functions, the time complexity calculation process of the atomic functions in the atomic function set is as follows: S211, set the loop body set to ,in Indicates loop variables, When the number of changes of the loop variables in the loop body set is an arbitrary constant, the time complexity of the loop variables in the loop body set is ; When the number of changes of the loop variables in the loop body set is recorded as an indefinite term , the time complexity of the loop variables in the loop body set is ; When the number of changes of the loop variables in the loop body set is recorded as an indefinite term And the change of the loop variables in the loop body set is doubled. At this time, the time complexity of the loop variables in the loop body set is ; Complete the judgment of the loop variables in the loop body set; S212, set the loop body nested set to ,in Indicates The loop body nesting relationship, when the loop variable in the loop body set and The loop body nesting relationship in the loop body nesting set is satisfied, and the loop variables in the loop body set is the outer loop, where and Respectively represent and loop variables, then the time complexity of the loop variables in the loop body set is ; Set a basic statement loop body execution statement set, select the most frequently executed statement in the basic statement loop body execution statement set, and the time complexity of the most frequently executed statement in the basic statement loop body execution statement set ; The atomic functions in the atomic function set include A basic statement loop executes a statement set to obtain the The most frequently executed statement in the basic statement loop execution statement set, then the time complexity of the atomic function in the atomic function set is ; S22, after obtaining the time complexity of the atomic functions in the atomic function set, the atomic functions in the atomic function set are backtracked according to S211 and S212 to obtain the time complexity of the initial function, the time complexity of the target function in the code fragment is calculated, and the time complexity set of the target function in the code fragment is generated. The time complexity threshold is set to , discard the code snippet where the objective function time complexity is greater than The target function is obtained to obtain the processed code fragment; S23, setting the target function set of the processed code fragment to ,in Indicates The objective function has a characteristic dimension of , generating the objective function matrix of the code snippet as follows, , in, Indicates The feature dimension is The objective function of Use the Black Kite optimization algorithm to optimize the running time of the code snippet in the program and set the fitness function ,in Indicates the interruption time of the service. Indicates the execution time of the code snippet, Indicates the error time. The specific process is as follows: S231, setting the objective function in the objective function matrix of the code fragment to represent the position of the black-winged kite, the number of individuals in the black-winged kite population is , the characteristic dimension of black kite is , No. Only feature dimension The calculation formula for the initial position of the black-winged kite is as follows:

[0031] in, Indicates Only feature dimension The initial position of the black-winged kite, Indicates A black kite Dimensional upper bound, Indicates A black kite Dimensional lower bound, represents a random number and ; S232, when attacking prey, the black-winged kite constantly changes its position, constantly optimizes the running time of the code snippet in the program, and sets the black-winged kite The position at the iteration is , Black-winged Kite The position at the iteration is , the maximum number of iterations is , the judgment coefficient of black-winged kite attacking prey is , represents a random number and , , the calculation formula is as follows, , , When the black kite When the code snippet is in the program, the running time of the optimized code snippet is completed. Iterations; S233, Black-winged kites introduce black-winged kite leaders during migration, and set the fitness of the black-winged kite population to , when the current fitness Greater than When the black-winged kite leader leads the black-winged kite population to migrate; set the migration process The position at the iteration is , during migration The position at the iteration is , the black kite migration process coefficient is , the Cauchy distribution function is , the leader position of the Black Winged Kite is , represents the running time of the code snippet in the program, and the calculation formula is as follows, , , The black-winged kite continuously searches for the minimum fitness during migration, sets the current number of iterations, and stops iterating when the current number of iterations is greater than the maximum number of iterations, thus completing the optimization of the running time of the code snippet in the program and obtaining the optimized code snippet. S3, generating a string matrix from the optimized code fragments, performing similarity detection on the strings in the string matrix, removing code fragments with similar features, obtaining similar code fragments, and recording the similar code fragments as the second code extraction iteration condition; The S3 comprises the following steps: S31, setting the optimized code snippet to include string, denoted as ,in Indicates strings, the feature dimension of the string is , get the string matrix as follows, , in, Indicates The feature dimension is String; The strings in the string matrix are converted into string feature vectors, two string feature vectors in the string matrix are taken, and the two string feature vectors in the string matrix are normalized to obtain a normalized vector and , the similarity calculation formula is as follows,

[0032] in, Represents the similarity of strings in the string matrix; S32, calculate the vector cosine value of the two string feature vectors in the string matrix, and set the similarity threshold to , the vector cosine value threshold is , when the vector cosine value of the two string feature vectors in the string matrix is ​​greater than or equal to And the similarity of the strings in the string matrix is ​​greater than or equal to When , the strings in the string matrix are the same, and the strings in the same string matrix are deleted; when the vector cosine value of the two string feature vectors in the string matrix is ​​less than And the similarity of the strings in the string matrix is ​​less than When , the strings in the string matrix are not the same, and the strings in the string matrix are retained; obtaining a similarity code fragment, and recording the similarity code fragment as a second code extraction iteration condition; S4. Combining the first code extraction iteration condition and the second code extraction iteration condition, obtaining a code snippet to be processed, running the code snippet to be processed, and adjusting the number of parallel threads, optimizing the code snippet running efficiency based on a differentiated creative search algorithm, and realizing code snippet extraction iteration; The S4 comprises the following steps: S41, the first code extraction iteration condition is the code snippet hotspot function, the second code extraction iteration condition is the similarity code snippet, the code snippet hotspot function is added to the similarity code snippet, the code snippet extraction is completed, and the code snippet set to be processed is obtained, which is recorded as ,in Indicates The code snippets to be processed are set to have a feature dimension of , generate a matrix of code snippets to be processed as follows, , in, Indicates The feature dimension is The code snippet to be processed; Use the differentiated creative search algorithm to optimize the number of parallel threads, optimize the running efficiency of the code snippets to be processed in the code snippet matrix to be processed, and set the code snippets to be processed in the code snippet matrix The number of solutions to the problem is , the problem solution dimension is , the code snippet matrix to be processed is recorded as the problem solution matrix, and the individual generation formula in the problem solution matrix is ​​as follows,

[0033] in, represents a random number and , Represents the problem solution matrix Dimensional upper bound, Represents the problem solution matrix Dimensional lower bound; S42. Setting fitness function ,in Indicates storage efficiency, represents the input efficiency, represents the output efficiency; calculate the fitness of individuals in the problem solution matrix, rank them from large to small according to their fitness in the problem solution matrix, and obtain the ranking number; in the differentiated knowledge acquisition stage, set the first The differential knowledge acquisition rate of the iteration is , No. The variable of differential knowledge acquisition in the iteration is , No. The individual ranking number of the iteration is , the maximum number of iterations is , the calculation formula is as follows, , , Set the first threshold to , when The number of iterations of differential knowledge acquisition variables is less than When the problem solution matrix is ​​selected, the individuals are selected as experimental individuals. The first iteration differentiates the knowledge acquisition rate to learn, absorb and integrate new knowledge or experience, and start the process of optimizing the number of parallel threads; set the The individual position of the iteration test is , No. The individual position in the solution matrix of the iteration problem is , then The formula for calculating the individual position in the solution matrix of the iteration problem is as follows:

[0034] After the individual positions in the problem solution matrix are replaced, a new problem solution matrix is ​​obtained, and the process of optimizing the number of parallel threads is completed. Iterations; S43. In the convergent thinking stage, a team leader is introduced. The team leader position satisfies the maximum fitness function. At this time, the code fragments to be processed in the code fragment matrix to be processed have the best running efficiency. Set the The position of the iteration team leader is , select the individual positions in the new problem solution matrix and , No. The iteration coefficients are , and , then the calculation formula for individual position update in the new problem solution matrix is ​​as follows: , , coefficient Continuously adjust the team leader position, set the current iteration number and the second threshold , when the current number of iterations is equal to the maximum number of iterations and the position of the individual in the new problem solution matrix is ​​less than , the position of the team leader is obtained; otherwise, repeat S42 and S43 until the current number of iterations is equal to the maximum number of iterations and the individual position in the new problem solution matrix is ​​less than ; Find the value of the horizontal coordinate of the corresponding position of the team leader position in the problem solution matrix, recorded as , is the number of parallel threads. The code fragments to be processed in the code fragment matrix are The number of parallel threads running is 1, and the code snippet is iteratively used.

[0035] This embodiment also discloses a system for a method of iteratively using code snippets extracted based on parallelization, which specifically includes: a code snippet hotspot function acquisition module, a code snippet running quality measurement module, a similarity code snippet detection module, and a parallel thread number adjustment module; The code snippet hot function acquisition module is used to classify the code snippet function call time proportion matrix to obtain the code snippet hot function; The code snippet execution quality measurement module is used to measure the code snippet execution quality using the time complexity of the target function in the code snippet and the execution time of the code snippet in the program; The similarity code snippet detection module is used to perform similarity detection on the character strings generated by the code snippets and delete the code snippets with similar features; The parallel thread number adjustment module is used to use a differentiated creative search algorithm to adjust the parallel thread number to optimize the running efficiency of the code snippet.

[0036] In the description of this specification, the description with reference to the terms "one embodiment", "example", "specific example", etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0037] The preferred embodiments of the invention disclosed above are only used to help explain the invention. The preferred embodiments do not describe all the details in detail, nor do they limit the invention to the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the invention, so that those skilled in the art can understand and use the invention well.

Claims

1. A method for iterative use of code snippet extraction based on parallelization, characterized in that: The steps include: S1. Obtain a code snippet function, generate a code snippet function call time proportion matrix, classify the code snippet function call time proportion matrix using a K-nearest neighbor method, obtain a code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition; S2. Use the time complexity of the target function in the code snippet and the running time of the code snippet in the program to measure the running quality of the code snippet, and optimize the running time of the code snippet in the program to obtain an optimized code snippet; S3, generating a string matrix according to the optimized code snippets, performing similarity detection on the strings in the string matrix, removing code snippets with similar features, obtaining similar code snippets, and recording the similar code snippets as the second code extraction iteration condition; S4. Combining the first code extraction iteration condition and the second code extraction iteration condition, obtain the code snippet to be processed, run the code snippet to be processed, and adjust the number of parallel threads to optimize the code snippet running efficiency and realize code snippet extraction iteration.

2. The method for iteratively using code snippets extracted based on parallelization according to claim 1, characterized in that: The S1 comprises the following steps: S11, obtaining a code snippet function, generating a code snippet function call time proportion matrix, and classifying the code snippet function call time proportion matrix using a K-nearest neighbor method to obtain a set of adjacent points; S12. Select the maximum weight value of the adjacent points in the adjacent point set, record it as the code snippet hotspot function, and record the code snippet hotspot function as the first code extraction iteration condition.

3. The method for iteratively using code snippets extracted based on parallelization according to claim 2, characterized in that: The S2 comprises the following steps: S21, setting the code fragment to include a target function to obtain a target function set, selecting a target function in the target function set as an initial function, wherein the call relationship set of the initial function includes an atomic function to obtain an atomic function set; S22, calculating the time complexity of the atomic functions in the atomic function set, and then backtracking the atomic functions in the atomic function set to obtain processed code fragments; S23. Use the Black Kite optimization algorithm to optimize the running time of the processed code snippet in the program to obtain an optimized code snippet.

4. The method for iteratively using code snippets extracted based on parallelization according to claim 2, characterized in that: The S21 comprises the following steps: S211, setting a loop body set, judging loop variables in the loop body set, and obtaining the time complexity of the loop variables in the loop body set; S212. The time complexity of the loop variables in the loop body set is obtained after the time complexity of the atomic functions in the atomic function set is processed according to the loop body nesting relationship and the basic statement loop body execution statement.

5. The method for iteratively using code snippets extracted based on parallelization according to claim 2, characterized in that: The S23 comprises the following steps: S231. Setting fitness function ,in Indicates the interruption time of the service. Indicates the execution time of the code snippet, Indicates the error time; Assume the number of black-winged kite population is , the characteristic dimension of black kite is , No. Only feature dimension The calculation formula for the initial position of the black-winged kite is as follows: , in, Indicates Only feature dimension The initial position of the black-winged kite, Indicates A black kite Dimensional upper bound, Indicates A black kite Dimensional lower bound, represents a random number and ; S232, Black-winged kite attacks prey, Black-winged kite constantly changes its position, constantly optimizes the running time of the code snippet in the program, and sets the Black-winged kite The position at the iteration is , Black-winged Kite The position at the iteration is , the maximum number of iterations is , the judgment coefficient of black-winged kite attacking prey is , represents a random number and , , Expressed as a constant, the calculation formula is as follows, , , When the black kite When the code snippet is in the same location, the running time of the optimized code snippet in the program is completed. Iterations; S233, Black-winged kites introduce black-winged kite leaders during migration, and set the fitness of the black-winged kite population to , when the current fitness Greater than When the black-winged kite leader leads the black-winged kite population to migrate; set the migration process The position at the iteration is , during migration The position at the iteration is , the black kite migration process coefficient is , the Cauchy distribution function is , the leader position of the Black Winged Kite is , represents the running time of the code snippet in the program, and the calculation formula is as follows, , , The black-winged kite continuously searches for the minimum fitness during migration and sets the current number of iterations. When the current number of iterations is greater than the maximum number of iterations, the iteration is stopped, and the running time of the code snippet in the program is optimized to obtain the optimized code snippet.

6. The method for iteratively using code snippets extracted based on parallelization according to claim 3, characterized in that: The S3 comprises the following steps: S31. Generate a string matrix according to the optimized code snippet, convert the strings in the string matrix into string feature vectors, calculate the similarity of the strings in the string matrix and the vector cosine value of the string feature vector, filter the strings in the string matrix, obtain similarity code snippets, and record the similarity code snippets as the second code extraction iteration condition.

7. The method for iteratively using code snippets extracted based on parallelization according to claim 4, characterized in that: The S4 comprises the following steps: S41. Combining the first code extraction iteration condition and the second code extraction iteration condition, obtaining code fragments to be processed, and generating a code fragment matrix to be processed; Use the differentiated creative search algorithm to optimize the number of parallel threads, optimize the running efficiency of the code snippets to be processed in the code snippet matrix to be processed, and set the code snippets to be processed in the code snippet matrix The number of solutions to the problem is , the problem solution dimension is , the code snippet matrix to be processed is recorded as the problem solution matrix, and the individual generation formula in the problem solution matrix is ​​as follows, , in, represents a random number and , Represents the problem solution matrix Dimensional upper bound, Represents the problem solution matrix Dimensional lower bound; S42. Setting fitness function ,in Represents storage efficiency, represents the input efficiency, represents the output efficiency; calculates the fitness of individuals in the problem solution matrix, ranks them from large to small according to their fitness in the problem solution matrix, and obtains the ranking number; in the differentiated knowledge acquisition stage, sets the first The differential knowledge acquisition rate of the iteration is , No. The variable of differential knowledge acquisition in the iteration is , No. The individual ranking number of the iteration is , the maximum number of iterations is , the calculation formula is as follows, , , Set the first threshold to , when The number of iterations of differential knowledge acquisition variables is less than When the problem solution matrix is ​​selected, the individuals are selected as experimental individuals. The first iteration differentiates the knowledge acquisition rate to learn, absorb and integrate new knowledge or experience, and start the process of optimizing the number of parallel threads; set the The individual position of the iteration test is , No. The individual position in the solution matrix of the iteration problem is , then The formula for calculating the individual position in the solution matrix of the iteration problem is as follows: , After the individual positions in the problem solution matrix are replaced, a new problem solution matrix is ​​obtained, and the process of optimizing the number of parallel threads is completed. Iterations; S43. In the convergent thinking stage, a team leader is introduced. The team leader position satisfies the maximum fitness function. At this time, the code fragments to be processed in the code fragment matrix to be processed have the best running efficiency. Set the The position of the iteration team leader is , select the individual positions in the new problem solution matrix respectively and , No. The iteration coefficients are , and , the maximum number of iterations is , then the calculation formula for individual position update in the new problem solution matrix is ​​as follows: , , coefficient Continuously adjust the team leader position, set the current iteration number and the second threshold , when the current number of iterations is equal to the maximum number of iterations and the position of the individual in the new problem solution matrix is ​​less than , the team leader position is obtained; otherwise, S42 and S43 are repeated until the current number of iterations is equal to the maximum number of iterations, and the individual position in the new problem solution matrix is ​​less than .

8. The method for iteratively using code snippets extracted based on parallelization according to claim 4, characterized in that: Find the value of the horizontal coordinate of the position of the team leader in the problem solution matrix, recorded as , is the number of parallel threads. The code fragments to be processed in the code fragment matrix are The number of parallel threads running is 1, and the code snippet is iteratively used.

9. A system for implementing the method for iterative use of code snippet extraction based on parallelization as claimed in any one of claims 1 to 8, characterized in that: Specifically include: code snippet hot function acquisition module, code snippet operation quality measurement module, similarity code snippet detection module and parallel thread number adjustment module; The code snippet hot function acquisition module is used to classify the code snippet function call time proportion matrix to obtain the code snippet hot function; The code snippet execution quality measurement module is used to measure the code snippet execution quality using the time complexity of the target function in the code snippet and the execution time of the code snippet in the program; The similarity code snippet detection module is used to perform similarity detection on the character strings generated by the code snippets and delete the code snippets with similar features; The parallel thread number adjustment module is used to use a differentiated creative search algorithm to adjust the number of parallel threads to optimize the running efficiency of the code snippet.

Citation Information

Patent Citations

  • Parallel computer system performance simulation method by combining serial simulation and parallel simulation

    CN101694628A

  • An Iterative Code Generation Method Based on Domain Knowledge Sharing

    CN102279750A

  • NLP and statistics-based attribution administrative division code identification method and system

    CN116303844A

  • Efficient code searching method based on product quantization

    CN117951251A

  • Code search system and method based on pre-training model

    CN117992572A