Ο Χάρος Posted September 4, 2017 Share Posted September 4, 2017 (edited) Hi, i want some expert to answer me in this question. Which is faster: 1. player.getObject().onDie(); 2. Interface.invoke("onDie", player); <-- Example syntax sucks afc.. just to make u understand I think reflection is no that fast but does it affect performance if for example we do 5 times reflection upon doAttack ? This mean every a player hit it does 5 invokes. PS. i did a berchmark in my code: It takes 46682 nanoseconds to invoke 5 methods. This mean 0.046682 milliseconds Edited September 4, 2017 by Ο Χάρος Quote Link to comment Share on other sites More sharing options...
Tryskell Posted September 4, 2017 Share Posted September 4, 2017 (edited) Added to the fact it's uglier to read, it's also slower (but not noticeable) to invoke rather than calling it. If you got no specific use to use invoke, dump it. Edited September 4, 2017 by Tryskell Quote Link to comment Share on other sites More sharing options...
Ο Χάρος Posted September 4, 2017 Author Share Posted September 4, 2017 20 minutes ago, Tryskell said: Added to the fact it's uglier to read, it's also slower (but not noticeable) to invoke rather than calling it. If you got no specific use to use invoke, dump it. It's lot of classes, lots of work and im thinking if it worh the work for just few nanoseconds.. it's really 0.006 max 0.1 millisecond difference to do 4 classes Quote Link to comment Share on other sites More sharing options...
SweeTs Posted September 4, 2017 Share Posted September 4, 2017 Access shitcoding since ever, so.. :D Oh cum on :3 how many account you have O.o Quote Link to comment Share on other sites More sharing options...
Ο Χάρος Posted September 4, 2017 Author Share Posted September 4, 2017 (edited) 41 minutes ago, SweeTs said: Access shitcoding since ever, so.. :D Oh cum on :3 how many account you have O.o i got chat banned :( Also shitcoding? i'm sure u remember codes i wrote year ago e.t.c come on skype and try me bitch i dare u ;( CUM ONNNNNNNNNNNNN Edited September 4, 2017 by Ο Χάρος Quote Link to comment Share on other sites More sharing options...
vampir Posted September 17, 2017 Share Posted September 17, 2017 I really doubt you will have any problems. There is possibility that after a lot of usages, JVM will optimize your code so invoke will run a faster but never as fast as direct call. You might want to debug invoke method to see how many actions are done, you wont be able to monitor native method call though. In Java 8 with Functional Interfaces most likely you dont really need to use reflection, so giving us what you really want to do and we might give you better solution. Next thing is that you need to make a lot of catches & in future while you or someone else changes name or parameters of doDie method, you will find out about this code when your server crashes. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.