-
-
Save RezzedUp/f5bc388cf9ab4592e701bf719ee70c53 to your computer and use it in GitHub Desktop.
Skript Variables vs. YAML Test 2.0: skript-yaml edition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Variables vs. YAML Test | |
# ----------------------- | |
# By: RezzedUp | |
# Version: 2.0 | |
# (skript-yaml edition) | |
# ----------------------- | |
# Requires: | |
# - Skript 2.2 (functions) | |
# - SkUtilities (files) | |
# - skript-yaml (yaml) | |
# | |
# | |
# 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: | |
delete {test::*} | |
# | |
# 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} | |
mod({_var-set-iterations}, {@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} variables..." | |
set {_var-set-start} to now | |
set {_var-set-iterations} to 0 | |
loop {_random::*}: | |
set {test::%loop-index%} to loop-value | |
add 1 to {_var-set-iterations} | |
mod({_var-set-iterations}, {@BREAK}) is 0 | |
{@PAUSE} | |
send "Set %{_var-set-iterations}% variables. %difference between now and {_var-set-start}% since starting." | |
set {_var-set-time} to difference between now and {_var-set-start} | |
send "&6Variable-set test:&f %{_var-set-time}%" | |
# | |
# Setup the file. | |
# | |
if file "test.yml" exists: | |
delete file "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} | |
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} variables..." | |
set {_var-get-start} to now | |
set {_var-get-iterations} to 0 | |
loop {_random::*}: | |
set {_var-get-value} to {test::%loop-index%} | |
add 1 to {_var-get-iterations} | |
mod({_var-get-iterations}, {@BREAK}) is 0 | |
{@PAUSE} | |
send "Got %{_var-get-iterations}% values. %difference between now and {_var-get-start}% since starting." | |
set {_var-get-time} to difference between now and {_var-get-start} | |
send "&6Variable-get test: &f%{_var-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} | |
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} variables test:&f %{_var-set-time}%" | |
send "&3Set {@TESTS} YAML values test: &f%{_yaml-set-time}%" | |
send "&bGet {@TESTS} variables test: &f%{_var-get-time}%" | |
send "&3Get {@TESTS} YAML values test: &f%{_yaml-get-time}%" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment