|
# |
|
# Variables vs. YAML Test |
|
# ----------------------- |
|
# By: RezzedUp |
|
# Version: 2.0 |
|
# (skript-yaml edition) |
|
# ----------------------- |
|
# Requires: |
|
# - Skript 2.2 (functions) |
|
# - skript-yaml (yaml) |
|
# - TXyaml |
|
# |
|
|
|
# |
|
# Change the values below to test different scenarios. |
|
# |
|
# PAUSE: How long the script should wait when it encounters its 'pause' state. |
|
# |
|
# TESTS: The number of tests to run. This value modifies the number of unique |
|
# values generated for 'set' tests, and how many values are randomly |
|
# selected for 'get' tests. |
|
# |
|
# BREAK: The number of tests to run before the script should enter its 'pause' state. |
|
# This prevents the server from crashing (because YAML is incredibly inefficient), |
|
# but please remember that this will also increase test-time. |
|
# |
|
|
|
options: |
|
|
|
PAUSE: wait 2 ticks |
|
|
|
TESTS: 2500 |
|
|
|
BREAK: 250 |
|
|
|
on script load: |
|
|
|
delete {test::*} |
|
|
|
on script unload: |
|
|
|
delete {test::*} |
|
|
|
function randomString(length: integer = 20, alphabet: string = "abcdefghijklmnopqrstuvwxyz0123456789-_") :: string: |
|
|
|
set {_chars::*} to {_alphabet} split at "" |
|
set {_string} to "" |
|
|
|
while length of {_string} is less than {_length}: |
|
|
|
set {_string} to "%{_string}%%random element out of {_chars::*}%" |
|
|
|
return {_string} |
|
|
|
command /test: |
|
aliases: /yamltest, /yaml-test |
|
trigger: |
|
|
|
# |
|
# Prepare random strings because the `randomString()` function is poor for performance |
|
# and hinders the score for setting variables. |
|
# |
|
|
|
send "&aGenerating random strings..." |
|
|
|
set {_randomly-generated-start} to now |
|
set {_randomly-generated-strings} to 0 |
|
|
|
while {_randomly-generated-strings} is less than {@TESTS}: |
|
|
|
set {_key} to randomString() |
|
|
|
{_random::%{_key}%} isn't set |
|
|
|
set {_random::%{_key}%} to {_key} |
|
add 1 to {_randomly-generated-strings} |
|
|
|
if mod({_randomly-generated-strings}, {@BREAK}) is 0: |
|
|
|
{@PAUSE} |
|
|
|
send "Generated %{_randomly-generated-strings}% strings. %difference between now and {_randomly-generated-start}% since starting." |
|
|
|
send "&6Generated %amount of {_random::*}% random strings: &f%difference between now and {_randomly-generated-start}%" |
|
|
|
# |
|
# VARIABLE SET TEST. |
|
# |
|
|
|
send "&aSetting {@TESTS} TXyaml..." |
|
|
|
set {_txyaml-set-start} to now |
|
set {_txyaml-set-iterations} to 0 |
|
|
|
loop {_random::*}: |
|
|
|
set yaml value "%loop-index%" from file "whatthehellisthis" from folder "pluginfolder" to loop-value |
|
add 1 to {_txyaml-set-iterations} |
|
|
|
if mod({_txyaml-set-iterations}, {@BREAK}) is 0: |
|
|
|
{@PAUSE} |
|
|
|
send "Set %{_txyaml-set-iterations}% TXyaml. %difference between now and {_txyaml-set-start}% since starting." |
|
|
|
set {_txyaml-set-time} to difference between now and {_txyaml-set-start} |
|
send "&6TXyaml-set test:&f %{_txyaml-set-time}%" |
|
|
|
# |
|
# Setup the file. |
|
# |
|
|
|
delete yml "test.yml" |
|
load yml "test.yml" |
|
|
|
# |
|
# YAML SET TEST. |
|
# |
|
|
|
send "&aSetting {@TESTS} YAML values..." |
|
|
|
set {_yaml-set-start} to now |
|
set {_yaml-set-iterations} to 0 |
|
|
|
loop {_random::*}: |
|
|
|
set skript-yaml value loop-index in "test" to loop-value |
|
add 1 to {_yaml-set-iterations} |
|
|
|
if mod({_yaml-set-iterations}, {@BREAK}) is 0: |
|
|
|
{@PAUSE} |
|
|
|
send "Set %{_yaml-set-iterations}% YAML values. %difference between now and {_yaml-set-start}% since starting." |
|
|
|
save yml "test" |
|
|
|
set {_yaml-set-time} to difference between now and {_yaml-set-start} |
|
send "&6YAML-set test: &f%{_yaml-set-time}%" |
|
|
|
# |
|
# VARIABLE GET TEST. |
|
# |
|
|
|
send "&aGetting {@TESTS} TXyaml..." |
|
|
|
set {_txyaml-get-start} to now |
|
set {_txyaml-get-iterations} to 0 |
|
|
|
loop {_random::*}: |
|
|
|
set {_txyaml-get-value} to yaml value "%loop-index%" from file "whatthehellisthis" from folder "pluginfolder" |
|
add 1 to {_txyaml-get-iterations} |
|
|
|
if mod({_txyaml-get-iterations}, {@BREAK}) is 0: |
|
|
|
{@PAUSE} |
|
|
|
send "Got %{_txyaml-get-iterations}% TXyaml values. %difference between now and {_txyaml-get-start}% since starting." |
|
|
|
set {_txyaml-get-time} to difference between now and {_txyaml-get-start} |
|
send "&6TXyaml-get test: &f%{_txyaml-get-time}%" |
|
|
|
# |
|
# YAML GET TEST. |
|
# |
|
|
|
send "&aGetting {@TESTS} random YAML values..." |
|
|
|
set {_yaml-get-start} to now |
|
set {_yaml-get-iterations} to 0 |
|
|
|
loop {_random::*}: |
|
|
|
set {_yaml-get-value} to skript-yaml value loop-index from "test" |
|
add 1 to {_yaml-get-iterations} |
|
|
|
if mod({_yaml-get-iterations}, {@BREAK}) is 0: |
|
|
|
{@PAUSE} |
|
|
|
send "Got %{_yaml-get-iterations}% YAML values. %difference between now and {_yaml-get-start}% since starting." |
|
|
|
set {_yaml-get-time} to difference between now and {_yaml-get-start} |
|
send "&6YAML-get test: &f%{_yaml-get-time}%" |
|
|
|
send "&f--- RESULTS: ---" |
|
send "&bSet {@TESTS} TXyaml values test:&f %{_txyaml-set-time}%" |
|
send "&3Set {@TESTS} skript-yaml values test: &f%{_yaml-set-time}%" |
|
send "&bGet {@TESTS} TXyaml test: &f%{_txyaml-get-time}%" |
|
send "&3Get {@TESTS} skript-yaml test: &f%{_yaml-get-time}%" |