Editing Scripts to be more Performance Friendly

I saw this scripting style plenty in people's scripts.

x1, x2, x3, x4 = 1, 2, 3, 4 It's not very performance friendly.

While yes, we're not building a super computer, ruby is quite slow already due to being an interpreter language, thus making it much slower would only hurt the end user. Who wants to play a laggy game? Or even create one? So let's not make a laggy script, shall we? : D

Back to the code from above, the following code can be run tested:

You can do a benchmark with the following code:

require 'benchmark'p 'test1'puts Benchmark.measure { @test1 = 0 @test2 = 0 @test3 = 0 @test4 = 0 10000000.times {@test1 = 1 @test2 = 1 @test3 = 1 @test4 = 1 } p @test1 p @test2 p @test3 p @test4}p 'test2'puts Benchmark.measure { @test1 = 0 @test2 = 0 @test3 = 0 @test4 = 0 10000000.times {@test1, @test2 = 1, 1 @test3, @test4 = 1, 1 } p @test1 p @test2 p @test3 p @test4}p 'test3'puts Benchmark.measure { @test1 = 0 @test2 = 0 @test3 = 0 @test4 = 0 10000000.times {@test1, @test2, @test3, @test4 = 1, 1, 1, 1} p @test1 p @test2 p @test3 p @test4}p 'test4'puts Benchmark.measure { @test1 = 0 @test2 = 0 @test3 = 0 @test4 = 0 10000000.times {@test1 = @test2 = @test3 = @test4 = 1} p @test1 p @test2 p @test3 p @test4} And the result:

"test1"1111 0.813000 0.000000 0.813000 ( 0.804143)"test2"1111 1.375000 0.000000 1.375000 ( 1.377975)"test3"1111 2.062000 0.000000 2.062000 ( 2.061459)"test4"1111 0.875000 0.000000 0.875000 ( 0.877620)Comma operator during assignment increases the performance cost rather significantly by factor around 2. Meanwhile, chaining the assignment operator (test4) only slightly increase the performance cost, thus it's relatively friendly to use.

Also, for RGSS scripting, drawing GUI takes tons of performance, skipping the redrawing process for same GUI over will reduce the performance, this can be done by creating a counter to check whether the GUI should be changed or not, or caching the GUI and only display it later on though there should be a good balance between the two.

Here's more trick on how to make your code more 'performance' friendly.

http://greyblake.com/blog/2012/09/02/ruby-perfomance-tricks/

If anyone could add up to the topic, that would be great.
Part of writting good code is knowing when to use the right tool. Multiple variable assignments using commas is not a bad practice per se, but you have to know when not to use it, when the performance boost is needed and when it is not.

Generally, if your script is not as fast as it should it is not because you used some multi comma assignments or some stuff like that but because you have some serious structural problems in your code.
Pretty sure the overhead for something like

a,b,c,d = 1,2,3,4Is from the creation of arrays on the right-hand side.
Code:
a = b = c = d = 1a = 1b = 1c = 1d = 1
Don't have the array issue.I only do it if I'm assigning a returned value from a method, and the method is returning an array.

Code:
x, y = get_position($game_player)# VSpos = get_position($game_player)x = pos[0]y = pos[1]

Original thread: https://forums.rpgmakerweb.com/threads/editing-scripts-to-be-more-performance-friendly.24364/