From 6bbe1d4b5fdb47f89ba40c498e5fa6fed5579e27 Mon Sep 17 00:00:00 2001 From: pwwang Date: Tue, 25 Jun 2024 12:40:33 -0700 Subject: [PATCH] mention rtoml 0.11+ can handle None-values --- README.md | 36 ++++++++++++++++---------------- reports/with_toml-test_latest.md | 36 ++++++++++++++++---------------- reports/with_toml-test_v1.2.0.md | 34 +++++++++++++++--------------- reports/with_toml-test_v1.3.0.md | 32 ++++++++++++++-------------- reports/with_toml-test_v1.4.0.md | 34 +++++++++++++++--------------- toml_bench/api.py | 29 +++++++++++++++++++++++++ toml_bench/cases/value_none.py | 8 +++---- 7 files changed, 119 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index c85e490..99062a1 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,9 @@ Literally `.dumps(None)` |toml|'NoneType' object is not iterable| |tomli/tomli_w|'NoneType' object has no attribute 'items'| |tomlkit|Expecting Mapping or TOML Container, given| -|rtoml|"null"| +|rtoml|"null"
---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
"@None"| |qtoml|'NoneType' object has no attribute 'items'| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ### Dumping key-`None` pair @@ -49,9 +49,9 @@ Literally `.dumps({"key": None})` |toml|| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = "null"
| +|rtoml|key = "null"

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = "@None"
| |qtoml|TOML cannot encode None| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ### Dumping list with `None` value @@ -65,9 +65,9 @@ Literally `.dumps({"key": [1, 2, 3, None, 5]})` |toml|key = [ 1, 2, 3, "None", 5,]
| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = [1, 2, 3, "null", 5]
| +|rtoml|key = [1, 2, 3, "null", 5]

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = [1, 2, 3, "@None", 5]
| |qtoml|bad type '' for dump_value| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ### Loading `None`-like values @@ -79,9 +79,9 @@ Literally `.loads('v1 = "null" v2 = "None"')` | |Loaded as| |-|-----------------------| |toml|{'v1': 'null', 'v2': 'None'}| -|tomli/tomli_w|{'v1': 'null', 'v2': 'None'}| +|tomli/tomli_w|module 'tomli_w' has no attribute 'loads'| |tomlkit|{'v1': 'null', 'v2': 'None'}| -|rtoml|{'v1': 'null', 'v2': 'None'}| +|rtoml|{'v1': 'null', 'v2': 'None'}
---
rtoml v0.11+ supports loading custom None values:
`rtoml.loads(data, none_value='None')`:
{'v1': 'null', 'v2': None}
`rtoml.loads(data, none_value='null')`:
{'v1': None, 'v2': 'None'}| |qtoml|{'v1': 'null', 'v2': 'None'}| |tomllib|{'v1': 'null', 'v2': 'None'}| @@ -320,11 +320,11 @@ provided by `rtoml` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|2.14s (5000 iterations)|0.74s (5000 iterations)| -|tomlkit|40.28s (5000 iterations)|1.01s (5000 iterations)| -|rtoml|0.38s (5000 iterations)|0.09s (5000 iterations)| -|qtoml|5.04s (5000 iterations)|1.92s (5000 iterations)| -|tomllib|2.05s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|2.14s (5000 iterations)|0.73s (5000 iterations)| +|tomlkit|39.78s (5000 iterations)|0.98s (5000 iterations)| +|rtoml|0.37s (5000 iterations)|0.08s (5000 iterations)| +|qtoml|4.99s (5000 iterations)|1.87s (5000 iterations)| +|tomllib|2.04s (5000 iterations)|Dumping not supported| ### Running speed with data provided by `tomli` @@ -337,11 +337,11 @@ provided by `tomli` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|1.40s (5000 iterations)|0.46s (5000 iterations)| -|tomlkit|26.10s (5000 iterations)|0.52s (5000 iterations)| -|rtoml|0.32s (5000 iterations)|0.17s (5000 iterations)| -|qtoml|3.72s (5000 iterations)|1.33s (5000 iterations)| -|tomllib|1.50s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|1.41s (5000 iterations)|0.46s (5000 iterations)| +|tomlkit|24.55s (5000 iterations)|0.51s (5000 iterations)| +|rtoml|0.32s (5000 iterations)|0.16s (5000 iterations)| +|qtoml|3.63s (5000 iterations)|1.25s (5000 iterations)| +|tomllib|1.44s (5000 iterations)|Dumping not supported| diff --git a/reports/with_toml-test_latest.md b/reports/with_toml-test_latest.md index 5a974c5..442bc17 100644 --- a/reports/with_toml-test_latest.md +++ b/reports/with_toml-test_latest.md @@ -25,9 +25,9 @@ Literally `.dumps(None)` |toml|'NoneType' object is not iterable| |tomli/tomli_w|'NoneType' object has no attribute 'items'| |tomlkit|Expecting Mapping or TOML Container, given| -|rtoml|"null"| +|rtoml|"null"
---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
"@None"| |qtoml|'NoneType' object has no attribute 'items'| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping key-`None` pair @@ -41,9 +41,9 @@ Literally `.dumps({"key": None})` |toml|| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = "null"
| +|rtoml|key = "null"

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = "@None"
| |qtoml|TOML cannot encode None| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping list with `None` value @@ -57,9 +57,9 @@ Literally `.dumps({"key": [1, 2, 3, None, 5]})` |toml|key = [ 1, 2, 3, "None", 5,]
| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = [1, 2, 3, "null", 5]
| +|rtoml|key = [1, 2, 3, "null", 5]

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = [1, 2, 3, "@None", 5]
| |qtoml|bad type '' for dump_value| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Loading `None`-like values @@ -71,9 +71,9 @@ Literally `.loads('v1 = "null" v2 = "None"')` | |Loaded as| |-|-----------------------| |toml|{'v1': 'null', 'v2': 'None'}| -|tomli/tomli_w|{'v1': 'null', 'v2': 'None'}| +|tomli/tomli_w|module 'tomli_w' has no attribute 'loads'| |tomlkit|{'v1': 'null', 'v2': 'None'}| -|rtoml|{'v1': 'null', 'v2': 'None'}| +|rtoml|{'v1': 'null', 'v2': 'None'}
---
rtoml v0.11+ supports loading custom None values:
`rtoml.loads(data, none_value='None')`:
{'v1': 'null', 'v2': None}
`rtoml.loads(data, none_value='null')`:
{'v1': None, 'v2': 'None'}| |qtoml|{'v1': 'null', 'v2': 'None'}| |tomllib|{'v1': 'null', 'v2': 'None'}| @@ -312,11 +312,11 @@ provided by `rtoml` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|2.14s (5000 iterations)|0.74s (5000 iterations)| -|tomlkit|40.28s (5000 iterations)|1.01s (5000 iterations)| -|rtoml|0.38s (5000 iterations)|0.09s (5000 iterations)| -|qtoml|5.04s (5000 iterations)|1.92s (5000 iterations)| -|tomllib|2.05s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|2.14s (5000 iterations)|0.73s (5000 iterations)| +|tomlkit|39.78s (5000 iterations)|0.98s (5000 iterations)| +|rtoml|0.37s (5000 iterations)|0.08s (5000 iterations)| +|qtoml|4.99s (5000 iterations)|1.87s (5000 iterations)| +|tomllib|2.04s (5000 iterations)|Dumping not supported| ## Running speed with data provided by `tomli` @@ -329,9 +329,9 @@ provided by `tomli` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|1.40s (5000 iterations)|0.46s (5000 iterations)| -|tomlkit|26.10s (5000 iterations)|0.52s (5000 iterations)| -|rtoml|0.32s (5000 iterations)|0.17s (5000 iterations)| -|qtoml|3.72s (5000 iterations)|1.33s (5000 iterations)| -|tomllib|1.50s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|1.41s (5000 iterations)|0.46s (5000 iterations)| +|tomlkit|24.55s (5000 iterations)|0.51s (5000 iterations)| +|rtoml|0.32s (5000 iterations)|0.16s (5000 iterations)| +|qtoml|3.63s (5000 iterations)|1.25s (5000 iterations)| +|tomllib|1.44s (5000 iterations)|Dumping not supported| diff --git a/reports/with_toml-test_v1.2.0.md b/reports/with_toml-test_v1.2.0.md index 31d41cd..e44a6dd 100644 --- a/reports/with_toml-test_v1.2.0.md +++ b/reports/with_toml-test_v1.2.0.md @@ -25,9 +25,9 @@ Literally `.dumps(None)` |toml|'NoneType' object is not iterable| |tomli/tomli_w|'NoneType' object has no attribute 'items'| |tomlkit|Expecting Mapping or TOML Container, given| -|rtoml|"null"| +|rtoml|"null"
---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
"@None"| |qtoml|'NoneType' object has no attribute 'items'| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping key-`None` pair @@ -41,9 +41,9 @@ Literally `.dumps({"key": None})` |toml|| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = "null"
| +|rtoml|key = "null"

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = "@None"
| |qtoml|TOML cannot encode None| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping list with `None` value @@ -57,9 +57,9 @@ Literally `.dumps({"key": [1, 2, 3, None, 5]})` |toml|key = [ 1, 2, 3, "None", 5,]
| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = [1, 2, 3, "null", 5]
| +|rtoml|key = [1, 2, 3, "null", 5]

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = [1, 2, 3, "@None", 5]
| |qtoml|bad type '' for dump_value| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Loading `None`-like values @@ -71,9 +71,9 @@ Literally `.loads('v1 = "null" v2 = "None"')` | |Loaded as| |-|-----------------------| |toml|{'v1': 'null', 'v2': 'None'}| -|tomli/tomli_w|{'v1': 'null', 'v2': 'None'}| +|tomli/tomli_w|module 'tomli_w' has no attribute 'loads'| |tomlkit|{'v1': 'null', 'v2': 'None'}| -|rtoml|{'v1': 'null', 'v2': 'None'}| +|rtoml|{'v1': 'null', 'v2': 'None'}
---
rtoml v0.11+ supports loading custom None values:
`rtoml.loads(data, none_value='None')`:
{'v1': 'null', 'v2': None}
`rtoml.loads(data, none_value='null')`:
{'v1': None, 'v2': 'None'}| |qtoml|{'v1': 'null', 'v2': 'None'}| |tomllib|{'v1': 'null', 'v2': 'None'}| @@ -312,11 +312,11 @@ provided by `rtoml` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|2.10s (5000 iterations)|0.74s (5000 iterations)| -|tomlkit|40.82s (5000 iterations)|0.99s (5000 iterations)| -|rtoml|0.37s (5000 iterations)|0.09s (5000 iterations)| -|qtoml|5.01s (5000 iterations)|1.88s (5000 iterations)| -|tomllib|2.06s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|2.09s (5000 iterations)|0.74s (5000 iterations)| +|tomlkit|39.62s (5000 iterations)|0.99s (5000 iterations)| +|rtoml|0.38s (5000 iterations)|0.08s (5000 iterations)| +|qtoml|5.08s (5000 iterations)|1.91s (5000 iterations)| +|tomllib|2.02s (5000 iterations)|Dumping not supported| ## Running speed with data provided by `tomli` @@ -329,9 +329,9 @@ provided by `tomli` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|1.42s (5000 iterations)|0.46s (5000 iterations)| -|tomlkit|25.31s (5000 iterations)|0.50s (5000 iterations)| +|tomli/tomli_w|1.41s (5000 iterations)|0.46s (5000 iterations)| +|tomlkit|24.56s (5000 iterations)|0.50s (5000 iterations)| |rtoml|0.32s (5000 iterations)|0.16s (5000 iterations)| -|qtoml|3.65s (5000 iterations)|1.28s (5000 iterations)| -|tomllib|1.54s (5000 iterations)|Dumping not supported| +|qtoml|3.68s (5000 iterations)|1.26s (5000 iterations)| +|tomllib|1.42s (5000 iterations)|Dumping not supported| diff --git a/reports/with_toml-test_v1.3.0.md b/reports/with_toml-test_v1.3.0.md index c19352d..b612d35 100644 --- a/reports/with_toml-test_v1.3.0.md +++ b/reports/with_toml-test_v1.3.0.md @@ -25,9 +25,9 @@ Literally `.dumps(None)` |toml|'NoneType' object is not iterable| |tomli/tomli_w|'NoneType' object has no attribute 'items'| |tomlkit|Expecting Mapping or TOML Container, given| -|rtoml|"null"| +|rtoml|"null"
---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
"@None"| |qtoml|'NoneType' object has no attribute 'items'| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping key-`None` pair @@ -41,9 +41,9 @@ Literally `.dumps({"key": None})` |toml|| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = "null"
| +|rtoml|key = "null"

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = "@None"
| |qtoml|TOML cannot encode None| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping list with `None` value @@ -57,9 +57,9 @@ Literally `.dumps({"key": [1, 2, 3, None, 5]})` |toml|key = [ 1, 2, 3, "None", 5,]
| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = [1, 2, 3, "null", 5]
| +|rtoml|key = [1, 2, 3, "null", 5]

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = [1, 2, 3, "@None", 5]
| |qtoml|bad type '' for dump_value| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Loading `None`-like values @@ -71,9 +71,9 @@ Literally `.loads('v1 = "null" v2 = "None"')` | |Loaded as| |-|-----------------------| |toml|{'v1': 'null', 'v2': 'None'}| -|tomli/tomli_w|{'v1': 'null', 'v2': 'None'}| +|tomli/tomli_w|module 'tomli_w' has no attribute 'loads'| |tomlkit|{'v1': 'null', 'v2': 'None'}| -|rtoml|{'v1': 'null', 'v2': 'None'}| +|rtoml|{'v1': 'null', 'v2': 'None'}
---
rtoml v0.11+ supports loading custom None values:
`rtoml.loads(data, none_value='None')`:
{'v1': 'null', 'v2': None}
`rtoml.loads(data, none_value='null')`:
{'v1': None, 'v2': 'None'}| |qtoml|{'v1': 'null', 'v2': 'None'}| |tomllib|{'v1': 'null', 'v2': 'None'}| @@ -312,11 +312,11 @@ provided by `rtoml` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|2.15s (5000 iterations)|0.75s (5000 iterations)| -|tomlkit|39.49s (5000 iterations)|0.99s (5000 iterations)| +|tomli/tomli_w|2.16s (5000 iterations)|0.74s (5000 iterations)| +|tomlkit|39.48s (5000 iterations)|1.00s (5000 iterations)| |rtoml|0.38s (5000 iterations)|0.09s (5000 iterations)| -|qtoml|4.97s (5000 iterations)|1.87s (5000 iterations)| -|tomllib|2.02s (5000 iterations)|Dumping not supported| +|qtoml|5.00s (5000 iterations)|1.87s (5000 iterations)| +|tomllib|2.08s (5000 iterations)|Dumping not supported| ## Running speed with data provided by `tomli` @@ -329,9 +329,9 @@ provided by `tomli` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|1.40s (5000 iterations)|0.47s (5000 iterations)| -|tomlkit|25.86s (5000 iterations)|0.50s (5000 iterations)| +|tomli/tomli_w|1.39s (5000 iterations)|0.47s (5000 iterations)| +|tomlkit|24.42s (5000 iterations)|0.50s (5000 iterations)| |rtoml|0.32s (5000 iterations)|0.16s (5000 iterations)| -|qtoml|3.71s (5000 iterations)|1.31s (5000 iterations)| -|tomllib|1.49s (5000 iterations)|Dumping not supported| +|qtoml|3.63s (5000 iterations)|1.25s (5000 iterations)| +|tomllib|1.38s (5000 iterations)|Dumping not supported| diff --git a/reports/with_toml-test_v1.4.0.md b/reports/with_toml-test_v1.4.0.md index 3ae2a08..0a93f5c 100644 --- a/reports/with_toml-test_v1.4.0.md +++ b/reports/with_toml-test_v1.4.0.md @@ -25,9 +25,9 @@ Literally `.dumps(None)` |toml|'NoneType' object is not iterable| |tomli/tomli_w|'NoneType' object has no attribute 'items'| |tomlkit|Expecting Mapping or TOML Container, given| -|rtoml|"null"| +|rtoml|"null"
---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
"@None"| |qtoml|'NoneType' object has no attribute 'items'| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping key-`None` pair @@ -41,9 +41,9 @@ Literally `.dumps({"key": None})` |toml|| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = "null"
| +|rtoml|key = "null"

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = "@None"
| |qtoml|TOML cannot encode None| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Dumping list with `None` value @@ -57,9 +57,9 @@ Literally `.dumps({"key": [1, 2, 3, None, 5]})` |toml|key = [ 1, 2, 3, "None", 5,]
| |tomli/tomli_w|Object of type is not TOML serializable| |tomlkit|Invalid type | -|rtoml|key = [1, 2, 3, "null", 5]
| +|rtoml|key = [1, 2, 3, "null", 5]

---
rtoml v0.11+ supports dumping None to a desired string:
`rtoml.dumps(data, none_value='@None')`:
key = [1, 2, 3, "@None", 5]
| |qtoml|bad type '' for dump_value| -|tomllib|Dumping not supported| +|tomllib|module 'tomllib' has no attribute 'dumps'| ## Loading `None`-like values @@ -71,9 +71,9 @@ Literally `.loads('v1 = "null" v2 = "None"')` | |Loaded as| |-|-----------------------| |toml|{'v1': 'null', 'v2': 'None'}| -|tomli/tomli_w|{'v1': 'null', 'v2': 'None'}| +|tomli/tomli_w|module 'tomli_w' has no attribute 'loads'| |tomlkit|{'v1': 'null', 'v2': 'None'}| -|rtoml|{'v1': 'null', 'v2': 'None'}| +|rtoml|{'v1': 'null', 'v2': 'None'}
---
rtoml v0.11+ supports loading custom None values:
`rtoml.loads(data, none_value='None')`:
{'v1': 'null', 'v2': None}
`rtoml.loads(data, none_value='null')`:
{'v1': None, 'v2': 'None'}| |qtoml|{'v1': 'null', 'v2': 'None'}| |tomllib|{'v1': 'null', 'v2': 'None'}| @@ -312,10 +312,10 @@ provided by `rtoml` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|2.05s (5000 iterations)|0.73s (5000 iterations)| -|tomlkit|40.15s (5000 iterations)|1.00s (5000 iterations)| -|rtoml|0.38s (5000 iterations)|0.08s (5000 iterations)| -|qtoml|5.04s (5000 iterations)|1.89s (5000 iterations)| +|tomli/tomli_w|2.09s (5000 iterations)|0.75s (5000 iterations)| +|tomlkit|39.63s (5000 iterations)|1.01s (5000 iterations)| +|rtoml|0.38s (5000 iterations)|0.09s (5000 iterations)| +|qtoml|5.02s (5000 iterations)|1.88s (5000 iterations)| |tomllib|2.03s (5000 iterations)|Dumping not supported| ## Running speed with data provided by `tomli` @@ -329,9 +329,9 @@ provided by `tomli` | |Loading speed|Dumping speed| |-|-|-| |toml|Excluded (heterogeneous arrays not supported)|Excluded (heterogeneous arrays not supported)| -|tomli/tomli_w|1.39s (5000 iterations)|0.46s (5000 iterations)| -|tomlkit|25.00s (5000 iterations)|0.50s (5000 iterations)| -|rtoml|0.32s (5000 iterations)|0.16s (5000 iterations)| -|qtoml|3.64s (5000 iterations)|1.25s (5000 iterations)| -|tomllib|1.42s (5000 iterations)|Dumping not supported| +|tomli/tomli_w|1.37s (5000 iterations)|0.45s (5000 iterations)| +|tomlkit|24.39s (5000 iterations)|0.51s (5000 iterations)| +|rtoml|0.33s (5000 iterations)|0.16s (5000 iterations)| +|qtoml|3.65s (5000 iterations)|1.27s (5000 iterations)| +|tomllib|1.43s (5000 iterations)|Dumping not supported| diff --git a/toml_bench/api.py b/toml_bench/api.py index bd2fba0..a141b03 100644 --- a/toml_bench/api.py +++ b/toml_bench/api.py @@ -65,6 +65,9 @@ def dump(self, data: Mapping[str, Any], path: PathLike) -> None: def version(self) -> str: return im.version(self.package.__name__) + dumps_none = dumps + loads_none = loads + class TOMLAPI(APIBase): _name = "toml" @@ -110,6 +113,32 @@ class RTOMLAPI(APIBase): package = rtoml repo = "https://github.com/samuelcolvin/rtoml" + def dumps_none(self, data: Any) -> str: + out = self.package.dumps(data) + version = tuple(map(int, self.version.split("."))) + if version < (0, 11, 0): + return out + + return ( + f"{out}\n---\nrtoml v0.11+ supports dumping None to a desired string:\n" + "`rtoml.dumps(data, none_value='@None')`:" + f"\n{self.package.dumps(data, none_value='@None')}" + ) + + def loads_none(self, data: str) -> Mapping[str, Any]: + out = self.package.loads(data) + version = tuple(map(int, self.version.split("."))) + if version < (0, 11, 0): + return out + + return ( + f"{out!r}\n---\nrtoml v0.11+ supports loading custom None values:" + "\n`rtoml.loads(data, none_value='None')`:" + f"\n{self.package.loads(data, none_value='None')}" + "\n`rtoml.loads(data, none_value='null')`:" + f"\n{self.package.loads(data, none_value='null')}" + ) + class QTOMLAPI(APIBase): _name = "qtoml" diff --git a/toml_bench/cases/value_none.py b/toml_bench/cases/value_none.py index 157e47d..7d35ca8 100644 --- a/toml_bench/cases/value_none.py +++ b/toml_bench/cases/value_none.py @@ -6,7 +6,7 @@ class BenchCaseDumpNone(BenchCase): def run(self) -> Any: try: - return self.api.dumps(None) + return self.api.dumps_none(None) except Exception as e: return e @@ -15,7 +15,7 @@ class BenchCaseDumpValueNone(BenchCase): def run(self) -> Any: try: - return self.api.dumps({"key": None}) + return self.api.dumps_none({"key": None}) except Exception as e: return e @@ -24,7 +24,7 @@ class BenchCaseDumpListWithNone(BenchCase): def run(self) -> Any: try: - return self.api.dumps({"key": [1, 2, 3, None, 5]}) + return self.api.dumps_none({"key": [1, 2, 3, None, 5]}) except Exception as e: return e @@ -33,6 +33,6 @@ class BenchCaseLoadNoneLike(BenchCase): def run(self) -> Any: try: - return self.api.loads('v1 = "null"\nv2 = "None"') + return self.api.loads_none('v1 = "null"\nv2 = "None"') except Exception as e: return e