From e5d33fb3eecdeaa56f4c5d02b71648ee41068709 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Thu, 8 Aug 2024 20:39:40 -0400 Subject: [PATCH 1/6] benchmark: add dotenv benchmark --- benchmark/fixtures/valid.env | 67 ++++++++++++++++++++++++++++++++++++ benchmark/misc/dotenv.js | 16 +++++++++ 2 files changed, 83 insertions(+) create mode 100644 benchmark/fixtures/valid.env create mode 100644 benchmark/misc/dotenv.js diff --git a/benchmark/fixtures/valid.env b/benchmark/fixtures/valid.env new file mode 100644 index 00000000000000..120488d57917e0 --- /dev/null +++ b/benchmark/fixtures/valid.env @@ -0,0 +1,67 @@ +BASIC=basic + +# COMMENTS=work +#BASIC=basic2 +#BASIC=basic3 + +# previous line intentionally left blank +AFTER_LINE=after_line +EMPTY= +EMPTY_SINGLE_QUOTES='' +EMPTY_DOUBLE_QUOTES="" +EMPTY_BACKTICKS=`` +SINGLE_QUOTES='single_quotes' +SINGLE_QUOTES_SPACED=' single quotes ' +DOUBLE_QUOTES="double_quotes" +DOUBLE_QUOTES_SPACED=" double quotes " +DOUBLE_QUOTES_INSIDE_SINGLE='double "quotes" work inside single quotes' +DOUBLE_QUOTES_WITH_NO_SPACE_BRACKET="{ port: $MONGOLAB_PORT}" +SINGLE_QUOTES_INSIDE_DOUBLE="single 'quotes' work inside double quotes" +BACKTICKS_INSIDE_SINGLE='`backticks` work inside single quotes' +BACKTICKS_INSIDE_DOUBLE="`backticks` work inside double quotes" +BACKTICKS=`backticks` +BACKTICKS_SPACED=` backticks ` +DOUBLE_QUOTES_INSIDE_BACKTICKS=`double "quotes" work inside backticks` +SINGLE_QUOTES_INSIDE_BACKTICKS=`single 'quotes' work inside backticks` +DOUBLE_AND_SINGLE_QUOTES_INSIDE_BACKTICKS=`double "quotes" and single 'quotes' work inside backticks` +EXPAND_NEWLINES="expand\nnew\nlines" +DONT_EXPAND_UNQUOTED=dontexpand\nnewlines +DONT_EXPAND_SQUOTED='dontexpand\nnewlines' +# COMMENTS=work +INLINE_COMMENTS=inline comments # work #very #well +INLINE_COMMENTS_SINGLE_QUOTES='inline comments outside of #singlequotes' # work +INLINE_COMMENTS_DOUBLE_QUOTES="inline comments outside of #doublequotes" # work +INLINE_COMMENTS_BACKTICKS=`inline comments outside of #backticks` # work +INLINE_COMMENTS_SPACE=inline comments start with a#number sign. no space required. +EQUAL_SIGNS=equals== +RETAIN_INNER_QUOTES={"foo": "bar"} +RETAIN_INNER_QUOTES_AS_STRING='{"foo": "bar"}' +RETAIN_INNER_QUOTES_AS_BACKTICKS=`{"foo": "bar's"}` +TRIM_SPACE_FROM_UNQUOTED= some spaced out string +SPACE_BEFORE_DOUBLE_QUOTES= "space before double quotes" +EMAIL=therealnerdybeast@example.tld + SPACED_KEY = parsed +EDGE_CASE_INLINE_COMMENTS="VALUE1" # or "VALUE2" or "VALUE3" + +MULTI_DOUBLE_QUOTED="THIS +IS +A +MULTILINE +STRING" + +MULTI_SINGLE_QUOTED='THIS +IS +A +MULTILINE +STRING' + +MULTI_BACKTICKED=`THIS +IS +A +"MULTILINE'S" +STRING` +export EXPORT_EXAMPLE = ignore export + +MULTI_NOT_VALID_QUOTE=" +MULTI_NOT_VALID=THIS +IS NOT MULTILINE diff --git a/benchmark/misc/dotenv.js b/benchmark/misc/dotenv.js new file mode 100644 index 00000000000000..1684ed30af9e04 --- /dev/null +++ b/benchmark/misc/dotenv.js @@ -0,0 +1,16 @@ +'use strict'; + +const { createBenchmark } = require('../common.js'); +const path = require('path'); + +const bench = createBenchmark(main, { + n: 3e4, +}); + +function main({ n }) { + bench.start(); + for (let i = 0; i < n; i++) { + process.loadEnvFile(path.resolve(__dirname, '../fixtures/valid.env')); + } + bench.end(n); +} From ae6506d143db1dbded2f1db5359e15aa76cf0a2d Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sat, 10 Aug 2024 09:59:19 -0400 Subject: [PATCH 2/6] Update dotenv.js --- benchmark/misc/dotenv.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/benchmark/misc/dotenv.js b/benchmark/misc/dotenv.js index 1684ed30af9e04..e35ecd38df6f77 100644 --- a/benchmark/misc/dotenv.js +++ b/benchmark/misc/dotenv.js @@ -6,11 +6,12 @@ const path = require('path'); const bench = createBenchmark(main, { n: 3e4, }); +const file = path.resolve(__dirname, '../fixtures/valid.env'); function main({ n }) { bench.start(); for (let i = 0; i < n; i++) { - process.loadEnvFile(path.resolve(__dirname, '../fixtures/valid.env')); + process.loadEnvFile(file); } bench.end(n); } From a6a8888e611939bc789fe5415c891a7d91da3f52 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Tue, 3 Sep 2024 21:16:22 -0400 Subject: [PATCH 3/6] Update dotenv.js --- benchmark/misc/dotenv.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/benchmark/misc/dotenv.js b/benchmark/misc/dotenv.js index e35ecd38df6f77..62f7ed52237ba4 100644 --- a/benchmark/misc/dotenv.js +++ b/benchmark/misc/dotenv.js @@ -2,16 +2,18 @@ const { createBenchmark } = require('../common.js'); const path = require('path'); +const fs = require('fs'); +const util = reuire('util'); const bench = createBenchmark(main, { n: 3e4, }); -const file = path.resolve(__dirname, '../fixtures/valid.env'); +const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env')); function main({ n }) { bench.start(); for (let i = 0; i < n; i++) { - process.loadEnvFile(file); + util.parseEnv(file); } bench.end(n); } From aafb0ace3eeebc7729d598f290a5023a2e5a0c67 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Tue, 3 Sep 2024 21:16:53 -0400 Subject: [PATCH 4/6] Update dotenv.js --- benchmark/misc/dotenv.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/misc/dotenv.js b/benchmark/misc/dotenv.js index 62f7ed52237ba4..13e57c8663595c 100644 --- a/benchmark/misc/dotenv.js +++ b/benchmark/misc/dotenv.js @@ -13,7 +13,7 @@ const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env')); function main({ n }) { bench.start(); for (let i = 0; i < n; i++) { - util.parseEnv(file); + util.parseEnv(env); } bench.end(n); } From 110dc784f11952cc7359e3bec9a5f4c57c746b20 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:37:34 -0400 Subject: [PATCH 5/6] fix --- benchmark/{misc/dotenv.js => util/parse-env.js} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename benchmark/{misc/dotenv.js => util/parse-env.js} (70%) diff --git a/benchmark/misc/dotenv.js b/benchmark/util/parse-env.js similarity index 70% rename from benchmark/misc/dotenv.js rename to benchmark/util/parse-env.js index 13e57c8663595c..023cdbc4cf5a33 100644 --- a/benchmark/misc/dotenv.js +++ b/benchmark/util/parse-env.js @@ -1,14 +1,15 @@ 'use strict'; const { createBenchmark } = require('../common.js'); -const path = require('path'); -const fs = require('fs'); -const util = reuire('util'); +const path = require('node:path'); +const fs = require('node:fs'); +const util = require('node:util'); const bench = createBenchmark(main, { n: 3e4, }); -const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env')); + +const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env'), 'utf-8'); function main({ n }) { bench.start(); From 34e8c3aec46075ef95e21bcd64e4876a9eec43ef Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Wed, 4 Sep 2024 18:34:44 -0400 Subject: [PATCH 6/6] Update parse-env.js --- benchmark/util/parse-env.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/benchmark/util/parse-env.js b/benchmark/util/parse-env.js index 023cdbc4cf5a33..1bcd08ba213b93 100644 --- a/benchmark/util/parse-env.js +++ b/benchmark/util/parse-env.js @@ -4,6 +4,7 @@ const { createBenchmark } = require('../common.js'); const path = require('node:path'); const fs = require('node:fs'); const util = require('node:util'); +const assert = require('node:assert'); const bench = createBenchmark(main, { n: 3e4, @@ -12,9 +13,11 @@ const bench = createBenchmark(main, { const env = fs.readFileSync(path.resolve(__dirname, '../fixtures/valid.env'), 'utf-8'); function main({ n }) { + let noDead; bench.start(); for (let i = 0; i < n; i++) { - util.parseEnv(env); + noDead = util.parseEnv(env); } bench.end(n); + assert(noDead !== undefined); }