1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Now you can use YAML!

Discussion in 'Skript' started by Pikachu, Nov 11, 2017.

Thread Status:
Not open for further replies.
  1. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    THE FOLLOWING ONLY APPLIES WHEN USING "skript-yaml" FOR YAML

    Why use YAML?

    What was wrong with YAML?

    How much better is it now?

    Using skript-yaml results in an insane increase in performance compared to skUtilities, skQuery and Skellett.
    • Before (without skript-yaml):
      [​IMG]
    • After (with skript-yaml):
      upload_2017-11-11_0-37-3.png
    Code (Skript):
    1. Setting 2500 variables...
    2. Set 250 variables. 0.26 seconds since starting.
    3. Set 500 variables. 0.47 seconds since starting.
    4. Set 750 variables. 0.69 seconds since starting.
    5. Set 1000 variables. 0.9 seconds since starting.
    6. Set 1250 variables. 1.24 seconds since starting.
    7. Set 1500 variables. 1.46 seconds since starting.
    8. Set 1750 variables. 1.62 seconds since starting.
    9. Set 2000 variables. 1.77 seconds since starting.
    10. Set 2250 variables. 1.91 seconds since starting.
    11. Set 2500 variables. 2.06 seconds since starting.
    12. Variable-set test: 2.06 seconds
    13. Setting 2500 YAML values...
    14. Set 250 YAML values. 0.01 seconds since starting.
    15. Set 500 YAML values. 0.02 seconds since starting.
    16. Set 750 YAML values. 0.02 seconds since starting.
    17. Set 1000 YAML values. 0.04 seconds since starting.
    18. Set 1250 YAML values. 0.04 seconds since starting.
    19. Set 1500 YAML values. 0.05 seconds since starting.
    20. Set 1750 YAML values. 0.06 seconds since starting.
    21. Set 2000 YAML values. 0.06 seconds since starting.
    22. Set 2250 YAML values. 0.06 seconds since starting.
    23. Set 2500 YAML values. 0.07 seconds since starting.
    24. YAML-set test: 0.17 seconds
    25. Testing 2500 random variables
    26. Got 250 values. 0.33 seconds since starting.
    27. Got 500 values. 0.59 seconds since starting.
    28. Got 750 values. 0.75 seconds since starting.
    29. Got 1000 values. 0.96 seconds since starting.
    30. Got 1250 values. 1.12 seconds since starting.
    31. Got 1500 values. 1.28 seconds since starting.
    32. Got 1750 values. 1.43 seconds since starting.
    33. Got 2000 values. 1.6 seconds since starting.
    34. Got 2250 values. 1.73 seconds since starting.
    35. Got 2500 values. 1.91 seconds since starting.
    36. Variable-get test: 1.91 seconds
    37. Testing 2500 random YAML values
    38. Got 250 YAML values. 0.15 seconds since starting.
    39. Got 500 YAML values. 0.28 seconds since starting.
    40. Got 750 YAML values. 0.41 seconds since starting.
    41. Got 1000 YAML values. 0.57 seconds since starting.
    42. Got 1250 YAML values. 0.71 seconds since starting.
    43. Got 1500 YAML values. 0.85 seconds since starting.
    44. Got 1750 YAML values. 0.98 seconds since starting.
    45. Got 2000 YAML values. 1.14 seconds since starting.
    46. Got 2250 YAML values. 1.27 seconds since starting.
    47. Got 2500 YAML values. 1.4 seconds since starting.
    48. YAML-get test: 1.4 seconds
    49. -- RESULTS: ---
    50. Set 2500 variables test: 2.06 seconds
    51. Set 2500 YAML values test: 0.17 seconds
    52. Get 2500 variables test: 1.91 seconds
    53. Get 2500 YAML values test: 1.4 seconds

    Should I go changing everything to YAML?

    No, absolutely not. Variables are still the preferred way of storing data within Skript. That said, skript-yaml does make YAML a hell of a lot more viable and flexible for more than just config files.

    Where can I get skript-yaml?

    You can find skript-yaml here.

    What did you use to test this?
    I made an edit of Rezz's yaml test.
    Code (Skript):
    1. options:
    2.  
    3.     PAUSE: wait 2 ticks
    4.  
    5.     SET_TESTS: 2500
    6.     SET_PAUSE: 250
    7.  
    8.     GET_TESTS: 2500
    9.     GET_PAUSE: 250
    10.  
    11. on script load:
    12.  
    13.     delete {test::*}
    14.  
    15. on script unload:
    16.  
    17.     delete {test::*}
    18.  
    19. function randomString(length: integer = 20, alphabet: string = "abcdefghijklmnopqrstuvwxyz0123456789-_") :: string:
    20.  
    21.     set {_chars::*} to {_alphabet} split at ""
    22.     set {_string} to ""
    23.  
    24.     while length of {_string} is less than {_length}:
    25.  
    26.         set {_string} to "%{_string}%%random element out of {_chars::*}%"
    27.    
    28.     return {_string}
    29.  
    30. command /test:
    31.     trigger:
    32.  
    33.         delete {test::*}
    34.    
    35.         broadcast "&aSetting {@SET_TESTS} variables..."
    36.    
    37.         set {_var-set-start} to now
    38.         set {_var-set-iterations} to 0
    39.    
    40.         while {_var-set-iterations} is less than {@SET_TESTS}:
    41.    
    42.             set {_key} to randomString()
    43.        
    44.             {test::%{_key}%} isn't set
    45.        
    46.             set {test::%{_key}%} to {_key}
    47.        
    48.             add 1 to {_var-set-iterations}
    49.        
    50.             mod({_var-set-iterations}, {@SET_PAUSE}) is 0
    51.        
    52.            
    53.        
    54.             broadcast "Set %{_var-set-iterations}% variables. %difference between now and {_var-set-start}% since starting."
    55.        
    56.         set {_var-set-time} to difference between now and {_var-set-start}
    57.         broadcast "&6Variable-set test:&f %{_var-set-time}%"
    58.        
    59.         if file "plugins/test/test.yml" exists:
    60.             delete file "plugins/test/test.yml"
    61.         load yml "plugins/test/test.yml"
    62.  
    63.         broadcast "&aSetting {@SET_TESTS} YAML values..."
    64.        
    65.         set {_yaml-set-start} to now
    66.         set {_yaml-set-iterations} to 0
    67.    
    68.         loop {test::*}:
    69.    
    70.             set skript-yaml value loop-index in "test" to loop-value
    71.             add 1 to {_yaml-set-iterations}
    72.        
    73.             mod({_yaml-set-iterations}, {@SET_PAUSE}) is 0
    74.        
    75.            
    76.        
    77.             broadcast "Set %{_yaml-set-iterations}% YAML values. %difference between now and {_yaml-set-start}% since starting."
    78.         save yml "test"
    79.         set {_yaml-set-time} to difference between now and {_yaml-set-start}
    80.         broadcast "&6YAML-set test: &f%{_yaml-set-time}%"
    81.    
    82.         #
    83.         #   GET TESTS
    84.         #
    85.         broadcast "&aTesting {@GET_TESTS} random variables"
    86.    
    87.         set {_var-get-start} to now
    88.    
    89.         loop {@GET_TESTS} times:
    90.    
    91.             set {_var-get-key} to a random element out of {test::*}
    92.             set {_var-get-value} to {test::%{_var-get-key}%}
    93.        
    94.             mod(loop-number, {@GET_PAUSE}) is 0
    95.        
    96.            
    97.    
    98.             broadcast "Got %loop-number% values. %difference between now and {_var-get-start}% since starting."
    99.    
    100.         set {_var-get-time} to difference between now and {_var-get-start}
    101.         broadcast "&6Variable-get test: &f%{_var-get-time}%"
    102.    
    103.         broadcast "&aTesting {@GET_TESTS} random YAML values"
    104.    
    105.         set {_yaml-get-start} to now
    106.    
    107.         loop {@GET_TESTS} times:
    108.    
    109.             set {_yaml-get-key} to a random element out of {test::*}
    110.             set {_yaml-get-value} to skript-yaml value {_yaml-get-key} from "test"
    111.             mod(loop-number, {@GET_PAUSE}) is 0
    112.        
    113.            
    114.    
    115.             broadcast "Got %loop-number% YAML values. %difference between now and {_yaml-get-start}% since starting."
    116.            
    117.         set {_yaml-get-time} to difference between now and {_yaml-get-start}
    118.         broadcast "&6YAML-get test: &f%{_yaml-get-time}%"
    119.    
    120.         broadcast "<light red>-- RESULTS: ---"
    121.         broadcast "&bSet {@SET_TESTS} variables test:&f %{_var-set-time}%"
    122.         broadcast "<yellow>Set {@SET_TESTS} YAML values test: &f%{_yaml-set-time}%"
    123.         broadcast "&bGet {@GET_TESTS} variables test: &f%{_var-get-time}%"
    124.         broadcast "<yellow>Get {@GET_TESTS} YAML values test: &f%{_yaml-get-time}%"
     
  2. Syst3ms

    Addon Developer

    Joined:
    Jan 24, 2017
    Messages:
    191
    Likes Received:
    22
    [​IMG]


    Nuff said.
     
  3. FUZIK

    FUZIK Active Member

    Joined:
    Jan 26, 2017
    Messages:
    115
    Likes Received:
    10
    thanks you!
    p.s. it does not seem on spaghetti code but many this waited
     
  4. EWS

    EWS Active Member

    Joined:
    Jan 26, 2017
    Messages:
    51
    Likes Received:
    27
    Medals:
    Nice project, but I think it's important to note that using add %objects% to {var::*} also has some serious performance problems.

    Adding 2500 variables to a 10000 variable list:
    Code (Text):
    1.  
    2. [23:54:57 INFO]: [Skript] # /testvar
    3. [23:55:08 INFO]: [Skript] # testvar took 11021.532949 milliseconds
    4.  
    It seems to parse everything everytime you add something to that list, causing a huge performance loss.

    Using random numbers to set variables:
    Code (Text):
    1.  
    2. command /testvar:
    3.    trigger:
    4.        loop 2500 times:
    5.            set {list::%a random integer between 100000000 and 99999999%} to "ABC"
    6.  
    Code (Text):
    1.  
    2. [23:54:03 INFO]: [Skript] # /testvar
    3. [23:54:03 INFO]: [Skript] # testvar took 15.564432 milliseconds
    4.  
    From 11 seconds to 0.015 seconds.
    I think that some part of your code is making the variable test set be slower, even though you don't use "add", as it seems to be pretty fast here.
     
  5. Pikachu

    Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    870
    Likes Received:
    139
    Medals:
    Good point, but i don't think its not a big deal because like I said in the post variables should still be used. The main point is still true regardless -- YAML is a fuckton faster than it was and its actually viable now.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...