Hey,
So recently I began rewriting a keyboard/mouse input system of mine due to discovering how inefficient it was, anyway, during this process, began to ensure my methods where faster than the default methods - or at least as quick...
First of all, I loaded / inserted the benchmarking script into my project.
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html
Secondly, I made a small test like so...
module Input def self.blankmethod(aarrgg) endendLOOPS = 500_000Benchmark.bm do |x| p "Input.test = " x.report { LOOPS.times { Input.press?
UP) } } p "Blank.test = " x.report { LOOPS.times { Input.blankmethod
UP) } } endThird - I hit play and viewed the results...
( user ) , ( system ) , ( total ) , ( real )Input.test = 0.109000 , 0.000000 , 0.109000 , 0.111007Blank.test = 0.140000 , 0.000000 , 0.140000 , 0.133007Now as you can see, to call a Input.blank method 500,000 times takes longer than calling Input.press?(buttonsymbol) (the same amount of times) does.
I mean, how is that possible?
How is one supposed to write a script that is just as / more efficient when I cannot even create a blank method that processes quicker? Anyone have any ideas on that?
So far I have managed to get my Input.update method running around 3-4x faster than normal input.update, but imo, the press and trigger methods are just as/more important in the long term goal of efficiency.
I guess I am just not able to comprehend how the press method runs faster than a blank method does. I mean, if press? was just calling pure C/C++ code then yea, i could understand, but if that was the case why is the input.update method dramatically inefficient. ?
So recently I began rewriting a keyboard/mouse input system of mine due to discovering how inefficient it was, anyway, during this process, began to ensure my methods where faster than the default methods - or at least as quick...
First of all, I loaded / inserted the benchmarking script into my project.
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html
Secondly, I made a small test like so...
module Input def self.blankmethod(aarrgg) endendLOOPS = 500_000Benchmark.bm do |x| p "Input.test = " x.report { LOOPS.times { Input.press?
( user ) , ( system ) , ( total ) , ( real )Input.test = 0.109000 , 0.000000 , 0.109000 , 0.111007Blank.test = 0.140000 , 0.000000 , 0.140000 , 0.133007Now as you can see, to call a Input.blank method 500,000 times takes longer than calling Input.press?(buttonsymbol) (the same amount of times) does.
I mean, how is that possible?
How is one supposed to write a script that is just as / more efficient when I cannot even create a blank method that processes quicker? Anyone have any ideas on that?
So far I have managed to get my Input.update method running around 3-4x faster than normal input.update, but imo, the press and trigger methods are just as/more important in the long term goal of efficiency.
I guess I am just not able to comprehend how the press method runs faster than a blank method does. I mean, if press? was just calling pure C/C++ code then yea, i could understand, but if that was the case why is the input.update method dramatically inefficient. ?
Last edited by a moderator:
