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.
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.