From 190f8352f05e7b71ef76187db6044616ad7d63a1 Mon Sep 17 00:00:00 2001 From: jelveh Date: Sun, 6 Jul 2025 17:52:32 -0700 Subject: [PATCH] Add performance tests for get and set methods in kv module - Introduced two new tests: testGetPerformance and testSetPerformance. - Each test measures the execution time of the respective method and asserts that it completes in under 100ms. - Ensured correct value retrieval and performance metrics are logged for both tests. --- src/puter-js/test/kv.test.js | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/puter-js/test/kv.test.js b/src/puter-js/test/kv.test.js index ed0444af3..a4f2fd2f8 100644 --- a/src/puter-js/test/kv.test.js +++ b/src/puter-js/test/kv.test.js @@ -503,4 +503,46 @@ window.kvTests = [ } } }, + { + name: "testGetPerformance", + description: "Test that get method takes less than 100ms", + test: async function() { + try { + // Set up a key-value pair first + await puter.kv.set('performanceTestKey', 'testValue'); + + // Measure the time it takes to get the value + const startTime = performance.now(); + const value = await puter.kv.get('performanceTestKey'); + const endTime = performance.now(); + + const duration = endTime - startTime; + + // Assert that the value is correct and timing is under 100ms + assert(value === 'testValue', "Failed to retrieve correct value"); + assert(duration < 100, `Get method took ${duration}ms, which exceeds the 100ms limit`); + + pass(`testGetPerformance passed: get took ${duration.toFixed(2)}ms`); + } catch (error) { + fail("testGetPerformance failed:", error); + } + } + }, + { + name: "testSetPerformance", + description: "Test that set method takes less than 100ms", + test: async function() { + try { + // Set up a key-value pair first + const startTime = performance.now(); + await puter.kv.set('performanceTestKey', 'testValue'); + const endTime = performance.now(); + const duration = endTime - startTime; + assert(duration < 100, `Set method took ${duration}ms, which exceeds the 100ms limit`); + pass(`testSetPerformance passed: set took ${duration.toFixed(2)}ms`); + } catch (error) { + fail("testSetPerformance failed:", error); + } + } + } ]