/**
* Measures the performance of text blocks for hypothesis validation.
*
* @param {string} textBlock - The text block to measure.
* @param {function} validationFunction - A function that validates the text block.
* Should return true if the hypothesis is supported, false otherwise.
* @param {number} iterations - The number of times to run the validation. Defaults to 100.
* @returns {object} An object containing the average validation time in milliseconds and the success rate.
*/
function measureTextBlockPerformance(textBlock, validationFunction, iterations = 100) {
const startTime = performance.now();
let successCount = 0;
for (let i = 0; i < iterations; i++) {
validationFunction(textBlock); // Run the validation function
if (validationFunction(textBlock)) {
successCount++;
}
}
const endTime = performance.now();
const elapsedTime = endTime - startTime;
const averageTime = elapsedTime / iterations;
const successRate = successCount / iterations;
return {
averageTime: averageTime,
successRate: successRate,
};
}
//Example Usage (for testing)
// function exampleValidation(text) {
// // Replace this with your actual validation logic
// return text.length > 10;
// }
//const results = measureTextBlockPerformance("This is a long text.", exampleValidation, 1000);
//console.log(results);
Add your comment