@@ -21,7 +21,7 @@ const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/parse_
2121const SERVER_URL = 'http://localhost:1337/parse' ;
2222const APP_ID = 'benchmark-app-id' ;
2323const MASTER_KEY = 'benchmark-master-key' ;
24- const ITERATIONS = parseInt ( process . env . BENCHMARK_ITERATIONS || '1000' , 10 ) ;
24+ const ITERATIONS = process . env . BENCHMARK_ITERATIONS ? parseInt ( process . env . BENCHMARK_ITERATIONS , 10 ) : undefined ;
2525const LOG_ITERATIONS = false ;
2626
2727// Parse Server instance
@@ -102,14 +102,21 @@ function resetParseServer() {
102102
103103/**
104104 * Measure average time for an async operation over multiple iterations.
105- * @param {Object } options - Measurement options
106- * @param {string } options.name - Name of the operation being measured
107- * @param {Function } options.operation - Async function to measure
108- * @param {number } [options.iterations=ITERATIONS] - Number of iterations to run
109- * @param {boolean } [options.skipWarmup=false] - Skip warmup phase
110- * @param {number } [options.dbLatency] - Artificial DB latency in milliseconds to apply during this benchmark
105+ * @param {Object } options Measurement options.
106+ * @param {string } options.name Name of the operation being measured.
107+ * @param {Function } options.operation Async function to measure.
108+ * @param {number } options.iterations Number of iterations to run; choose a value that is high
109+ * enough to create reliable benchmark metrics with low variance but low enough to keep test
110+ * duration reasonable around <=10 seconds.
111+ * @param {boolean } [options.skipWarmup=false] Skip warmup phase.
112+ * @param {number } [options.dbLatency] Artificial DB latency in milliseconds to apply during
113+ * this benchmark.
111114 */
112- async function measureOperation ( { name, operation, iterations = ITERATIONS , skipWarmup = false , dbLatency } ) {
115+ async function measureOperation ( { name, operation, iterations, skipWarmup = false , dbLatency } ) {
116+ // Override iterations if global ITERATIONS is set
117+ iterations = ITERATIONS || iterations ;
118+
119+ // Determine warmup count (20% of iterations)
113120 const warmupCount = skipWarmup ? 0 : Math . floor ( iterations * 0.2 ) ;
114121 const times = [ ] ;
115122
@@ -198,6 +205,7 @@ async function benchmarkObjectCreate() {
198205
199206 return measureOperation ( {
200207 name : 'Object Create' ,
208+ iterations : 1_000 ,
201209 operation : async ( ) => {
202210 const TestObject = Parse . Object . extend ( 'BenchmarkTest' ) ;
203211 const obj = new TestObject ( ) ;
@@ -217,7 +225,7 @@ async function benchmarkObjectRead() {
217225 const TestObject = Parse . Object . extend ( 'BenchmarkTest' ) ;
218226 const objects = [ ] ;
219227
220- for ( let i = 0 ; i < ITERATIONS ; i ++ ) {
228+ for ( let i = 0 ; i < 1_000 ; i ++ ) {
221229 const obj = new TestObject ( ) ;
222230 obj . set ( 'testField' , `read-test-${ i } ` ) ;
223231 objects . push ( obj ) ;
@@ -229,6 +237,7 @@ async function benchmarkObjectRead() {
229237
230238 return measureOperation ( {
231239 name : 'Object Read' ,
240+ iterations : 1_000 ,
232241 operation : async ( ) => {
233242 const query = new Parse . Query ( 'BenchmarkTest' ) ;
234243 await query . get ( objects [ counter ++ % objects . length ] . id ) ;
@@ -244,7 +253,7 @@ async function benchmarkObjectUpdate() {
244253 const TestObject = Parse . Object . extend ( 'BenchmarkTest' ) ;
245254 const objects = [ ] ;
246255
247- for ( let i = 0 ; i < ITERATIONS ; i ++ ) {
256+ for ( let i = 0 ; i < 1_000 ; i ++ ) {
248257 const obj = new TestObject ( ) ;
249258 obj . set ( 'testField' , `update-test-${ i } ` ) ;
250259 obj . set ( 'counter' , 0 ) ;
@@ -257,6 +266,7 @@ async function benchmarkObjectUpdate() {
257266
258267 return measureOperation ( {
259268 name : 'Object Update' ,
269+ iterations : 1_000 ,
260270 operation : async ( ) => {
261271 const obj = objects [ counter ++ % objects . length ] ;
262272 obj . increment ( 'counter' ) ;
@@ -287,6 +297,7 @@ async function benchmarkSimpleQuery() {
287297
288298 return measureOperation ( {
289299 name : 'Simple Query' ,
300+ iterations : 1_000 ,
290301 operation : async ( ) => {
291302 const query = new Parse . Query ( 'BenchmarkTest' ) ;
292303 query . equalTo ( 'category' , counter ++ % 10 ) ;
@@ -303,6 +314,7 @@ async function benchmarkBatchSave() {
303314
304315 return measureOperation ( {
305316 name : 'Batch Save (10 objects)' ,
317+ iterations : 1_000 ,
306318 operation : async ( ) => {
307319 const TestObject = Parse . Object . extend ( 'BenchmarkTest' ) ;
308320 const objects = [ ] ;
@@ -327,6 +339,7 @@ async function benchmarkUserSignup() {
327339
328340 return measureOperation ( {
329341 name : 'User Signup' ,
342+ iterations : 500 ,
330343 operation : async ( ) => {
331344 counter ++ ;
332345 const user = new Parse . User ( ) ;
@@ -359,6 +372,7 @@ async function benchmarkUserLogin() {
359372
360373 return measureOperation ( {
361374 name : 'User Login' ,
375+ iterations : 500 ,
362376 operation : async ( ) => {
363377 const userCreds = users [ counter ++ % users . length ] ;
364378 await Parse . User . logIn ( userCreds . username , userCreds . password ) ;
@@ -379,8 +393,8 @@ async function benchmarkQueryWithInclude() {
379393 return measureOperation ( {
380394 name : 'Query with Include (2 levels)' ,
381395 skipWarmup : true ,
382- dbLatency : 10 ,
383- iterations : 10 ,
396+ dbLatency : 100 ,
397+ iterations : 100 ,
384398 operation : async ( ) => {
385399 // Create 10 Level2 objects
386400 const level2Objects = [ ] ;
@@ -424,7 +438,6 @@ async function benchmarkQueryWithInclude() {
424438 */
425439async function runBenchmarks ( ) {
426440 logInfo ( 'Starting Parse Server Performance Benchmarks...' ) ;
427- logInfo ( `Iterations per benchmark: ${ ITERATIONS } ` ) ;
428441
429442 let server ;
430443
0 commit comments