Skip to content

Commit

Permalink
Add benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyadn committed Oct 12, 2023
1 parent b203ac4 commit b1903c3
Show file tree
Hide file tree
Showing 30 changed files with 22,029 additions and 3 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,13 @@ Under development.
## License

MIT

## References

[TOML v1.0.0 Official Specs](https://toml.io/en/v1.0.0)

[TOML GitHub Project](https://github.com/toml-lang/toml)

[TOML Test](https://github.com/toml-lang/toml-test)

[iarna-toml](https://github.com/iarna/iarna-toml)
27 changes: 27 additions & 0 deletions benchmark/benchmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Benchmark from 'benchmark';
import glob from 'glob';
import fs from 'fs';
import jstoml from '../src';

const suite = new Benchmark.Suite();

const cases = glob.sync('benchmark/case/*.toml');
const contents = {};

for (const testCase of cases) {
const testName = testCase.split('/').pop().replace('.toml', '');
contents[testName] = fs.readFileSync(testCase, 'utf8');
suite.add(testName, () => {
jstoml.load(contents[testName]);
});
}

suite.on('cycle', (event: { target: never }) => {
console.log(String(event.target));
});

suite.on('error', (event: { target: { error: never } }) => {
console.error(event.target.error);
});

suite.run();
1 change: 1 addition & 0 deletions benchmark/case/01-small-doc-mixed-type-inline-array.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example = [ 1.2, 17, true, 'abc', [], {} ]
246 changes: 246 additions & 0 deletions benchmark/case/0A-spec-01-example-v0.4.0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
################################################################################
## Comment

# Speak your mind with the hash symbol. They go from the symbol to the end of
# the line.


################################################################################
## Table

# Tables (also known as hash tables or dictionaries) are collections of
# key/value pairs. They appear in square brackets on a line by themselves.

[table]

key = "value" # Yeah, you can do this.

# Nested tables are denoted by table names with dots in them. Name your tables
# whatever crap you please, just don't use #, ., [ or ].

[table.subtable]

key = "another value"

# You don't need to specify all the super-tables if you don't want to. TOML
# knows how to do it for you.

# [x] you
# [x.y] don't
# [x.y.z] need these
[x.y.z.w] # for this to work


################################################################################
## Inline Table

# Inline tables provide a more compact syntax for expressing tables. They are
# especially useful for grouped data that can otherwise quickly become verbose.
# Inline tables are enclosed in curly braces `{` and `}`. No newlines are
# allowed between the curly braces unless they are valid within a value.

[table.inline]

name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }


################################################################################
## String

# There are four ways to express strings: basic, multi-line basic, literal, and
# multi-line literal. All strings must contain only valid UTF-8 characters.

[string.basic]

basic = "I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."

[string.multiline]

# The following strings are byte-for-byte equivalent:
key1 = "One\nTwo"
key2 = """One\nTwo"""
key3 = """
One
Two"""

[string.multiline.continued]

# The following strings are byte-for-byte equivalent:
key1 = "The quick brown fox jumps over the lazy dog."

key2 = """
The quick brown \
fox jumps over \
the lazy dog."""

key3 = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""

[string.literal]

# What you see is what you get.
winpath = 'C:\Users\nodejs\templates'
winpath2 = '\\ServerX\admin$\system32\'
quoted = 'Tom "Dubs" Preston-Werner'
regex = '<\i\c*\s*>'


[string.literal.multiline]

regex2 = '''I [dw]on't need \d{2} apples'''
lines = '''
The first newline is
trimmed in raw strings.
All other whitespace
is preserved.
'''


################################################################################
## Integer

# Integers are whole numbers. Positive numbers may be prefixed with a plus sign.
# Negative numbers are prefixed with a minus sign.

[integer]

key1 = +99
key2 = 42
key3 = 0
key4 = -17

[integer.underscores]

# For large numbers, you may use underscores to enhance readability. Each
# underscore must be surrounded by at least one digit.
key1 = 1_000
key2 = 5_349_221
key3 = 1_2_3_4_5 # valid but inadvisable


################################################################################
## Float

# A float consists of an integer part (which may be prefixed with a plus or
# minus sign) followed by a fractional part and/or an exponent part.

[float.fractional]

key1 = +1.0
key2 = 3.1415
key3 = -0.01

[float.exponent]

key1 = 5e+22
key2 = 1e6
key3 = -2E-2

[float.both]

key = 6.626e-34

[float.underscores]

key1 = 9_224_617.445_991_228_313
# We support values like this, but toml-j0.4 does not and I'd still like
# values out of it
#key2 = 1e1_000


################################################################################
## Boolean

# Booleans are just the tokens you're used to. Always lowercase.

[boolean]

True = true
False = false


################################################################################
## Datetime

# Datetimes are RFC 3339 dates.

[datetime]

key1 = 1979-05-27T07:32:00Z
key2 = 1979-05-27T00:32:00-07:00
key3 = 1979-05-27T00:32:00.999999-07:00


################################################################################
## Array

# Arrays are square brackets with other primitives inside. Whitespace is
# ignored. Elements are separated by commas. Data types may not be mixed.

[array]

key1 = [ 1, 2, 3 ]
key2 = [ "red", "yellow", "green" ]
key3 = [ [ 1, 2 ], [3, 4, 5] ]
key4 = [ [ 1, 2 ], ["a", "b", "c"] ] # this is ok

# Arrays can also be multiline. So in addition to ignoring whitespace, arrays
# also ignore newlines between the brackets. Terminating commas are ok before
# the closing bracket.

key5 = [
1, 2, 3
]
key6 = [
1,
2, # this is ok
]


################################################################################
## Array of Tables

# These can be expressed by using a table name in double brackets. Each table
# with the same double bracketed name will be an element in the array. The
# tables are inserted in the order encountered.

[[products]]

name = "Hammer"
sku = 738594937

[[products]]

[[products]]

name = "Nail"
sku = 284758393
color = "gray"


# You can create nested arrays of tables as well.

[[fruit]]
name = "apple"

[fruit.physical]
color = "red"
shape = "round"

[[fruit.variety]]
name = "red delicious"

[[fruit.variety]]
name = "granny smith"

[[fruit]]
name = "banana"

[[fruit.variety]]
name = "plantain"
36 changes: 36 additions & 0 deletions benchmark/case/0A-spec-02-example-hard-unicode.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Tèƨƭ ƒïℓè ƒôř TÓM£

# Óñℓ¥ ƭλïƨ ôñè ƭřïèƨ ƭô è₥úℓáƭè á TÓM£ ƒïℓè ωřïƭƭèñ β¥ á úƨèř ôƒ ƭλè ƙïñδ ôƒ ƥářƨèř ωřïƭèřƨ ƥřôβáβℓ¥ λáƭè
# Tλïƨ ƥářƭ ¥ôú'ℓℓ řèáℓℓ¥ λáƭè

[the]
test_string = "Ýôú'ℓℓ λáƭè ₥è áƒƭèř ƭλïƨ - #" # " Âññô¥ïñϱ, ïƨñ'ƭ ïƭ?


[the.hard]
test_array = [ "] ", " # "] # ] Tλèřè ¥ôú ϱô, ƥářƨè ƭλïƨ!
test_array2 = [ "Tèƨƭ #11 ]ƥřôƲèδ ƭλáƭ", "Éжƥèřï₥èñƭ #9 ωáƨ á ƨúççèƨƨ" ]
# Ýôú δïδñ'ƭ ƭλïñƙ ïƭ'δ áƨ èáƨ¥ áƨ çλúçƙïñϱ ôúƭ ƭλè ℓáƨƭ #, δïδ ¥ôú?
another_test_string = "§á₥è ƭλïñϱ, βúƭ ωïƭλ á ƨƭřïñϱ #"
harder_test_string = " Âñδ ωλèñ \"'ƨ ářè ïñ ƭλè ƨƭřïñϱ, áℓôñϱ ωïƭλ # \"" # "áñδ çô₥₥èñƭƨ ářè ƭλèřè ƭôô"
# Tλïñϱƨ ωïℓℓ ϱèƭ λářδèř

[the.hard."βïƭ#"]
"ωλáƭ?" = "Ýôú δôñ'ƭ ƭλïñƙ ƨô₥è úƨèř ωôñ'ƭ δô ƭλáƭ?"
multi_line_array = [
"]",
# ] Óλ ¥èƨ Ì δïδ
]

# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test

#[error] ïƒ ¥ôú δïδñ'ƭ çáƭçλ ƭλïƨ, ¥ôúř ƥářƨèř ïƨ βřôƙèñ
#string = "Âñ¥ƭλïñϱ ôƭλèř ƭλáñ ƭáβƨ, ƨƥáçèƨ áñδ ñèωℓïñè áƒƭèř á ƙè¥ϱřôúƥ ôř ƙè¥ Ʋáℓúè ƥáïř λáƨ èñδèδ ƨλôúℓδ ƥřôδúçè áñ èřřôř úñℓèƨƨ ïƭ ïƨ á çô₥₥èñƭ" ℓïƙè ƭλïƨ

#array = [
# "Tλïƨ ₥ïϱλƭ ₥ôƨƭ ℓïƙèℓ¥ λáƥƥèñ ïñ ₥úℓƭïℓïñè ářřá¥ƨ",
# £ïƙè λèřè,
# "ôř λèřè,
# áñδ λèřè"
# ] Éñδ ôƒ ářřᥠçô₥₥èñƭ, ƒôřϱôƭ ƭλè #
#number = 3.14 ƥï <--áϱáïñ ƒôřϱôƭ ƭλè #
Loading

0 comments on commit b1903c3

Please sign in to comment.