Around this time, I decided to do a few tests, and I worked them out all under the same circumstances:
- No other programs running during all testing
- Kept the same room-size throughout each test ( 32x32 ), no drawing, black background
- Only made changes to the code in the create event of the one object I had in the room
- All tests were done seven times, consecutively
- Did not use the game_restart() function, just quit game and ran a new instance of the test
- Done in GM8 Registered
---Here are the tests ---
Test 1 : Executed the following piece of code WITHOUT the use of scripts
var t;
t = current_time;
repeat ( 25000 )
{ x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0; }
show_message((current_time-t));Test 2 : Executed the following piece of code WITH a script called 'tst'
In this test, script 'tst' contained the following code:
repeat ( 4 )
{ x = 0 ; y = 0; }The test was executed as follows:
var t;
t = current_time;
repeat ( 25000 )
{ tst(); }
show_message((current_time-t));Test 3 : Executed the following piece of code WITH a script called 'tst'
In this test, script 'tst' contained the following code:
x = 0 ; y = 0; x = 0 ; y = 0; x = 0 ; y = 0; x = 0 ; y = 0;
The test was executed exactly the same as Test 2
Test 4 : Executed the following piece of code WITH a script called 'tst'
In this test, script 'tst' contained the following code:
x = 0; y = 0; x = 0; y = 0; x = 0; y = 0; x = 0; y = 0;
The test was executed exactly the same as Test 2 and Test 3
Test 5 : Executed the following piece of code WITH a script called 'tst'
In this test, script 'tst' contained the following code:
x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0;
The test was executed exactly the same as Test 2, Test 3, and Test 4
Test 6 : Executed the following piece of code WITH a script called 'one_big_gigantic_script_name_to_tst_this_scrpt_4real'
In this test, script 'one_big_gigantic_script_name_to_tst_this_scrpt_4real' contained the following code:
x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0 ; x = 0 ; y = 0;
The test was executed exactly the same as Test 2, Test 3, Test 4, and Test 5
---Here are the results ---
Test 1 : Average time to calculate: .11 seconds
Trial 1: .11s, Trial 2: .11s, Trial 3: .09s, Trial 4: .11s, Trial 5: .12s, Trial 6: .13s, Trial 7: .08s
Test 2 : Average time to calculate: 1.91 seconds
Trial 1: 1.89s, Trial 2: 1.93s, Trial 3: 1.90s, Trial 4: 1.92s, Trial 5: 1.90s, Trial 6: 1.86s, Trial 7: 1.97s
Test 3 : Average time to calculate: 1.84 seconds
Trial 1: 1.86s, Trial 2: 1.79s, Trial 3: 1.83s, Trial 4: 1.83s, Trial 5: 1.84s, Trial 6: 1.84s, Trial 7: 1.90s
Test 4 : Average time to calculate: 1.88 seconds
Trial 1: 1.98s, Trial 2: 1.83s, Trial 3: 1.93s, Trial 4: 1.79s, Trial 5: 1.84s, Trial 6: 1.92s, Trial 7: 1.86s
Test 5 : Average time to calculate: 1.82 seconds
Trial 1: 1.79s, Trial 2: 1.84s, Trial 3: 1.76s, Trial 4: 1.84s, Trial 5: 1.81s, Trial 6: 1.84s, Trial 7: 1.86s
Test 6 : Average time to calculate: 1.86 seconds
Trial 1: 1.87s, Trial 2: 1.86s, Trial 3: 1.92s, Trial 4: 1.78s, Trial 5: 1.86s, Trial 6: 1.83s, Trial 7: 1.89s
---Conclusions/What I learned ---
The most important thing I picked up from doing this test, is that scripts can slow down your game, albeit not by much. If you are using nested-loops and running scripts nested in scripts in those nested-loops, you may want to just bite the bullet and type it out into the code editor and ditch the scripts.
Secondly, make sure you condense your code as much as possible. That doesn't mean fit everything into one line, but make sure if you have extra lines at the end of your code or scripts, remove them! Of course, as usual, keep your code readable, neat, and most importantly, to your liking. Just keep the lines of code to a minimum.
Lastly, keep your script names shorter. As you can see, the only difference between Test 5 and Test 6, is that Test 6 has a longer ( and more ridiculous ) name. Script names, according to this test, affect their calling speed. It makes sense; long name = long call times. So be sure to shorten the names, but also keep them recognizable, especially if it is an example or engine other users will be working with.
My final words on this would be, keep everything short, sweet, and to the point. It will save your processor some unneeded calculations, and will increase its performance, especially in cases where loops are used often. I hope this helps someone, somewhere!











