Ο Χάρος Posted September 4, 2017 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 Ο Χάρος
Tryskell Posted September 4, 2017 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
Ο Χάρος Posted September 4, 2017 Author 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
SweeTs Posted September 4, 2017 Posted September 4, 2017 Access shitcoding since ever, so.. :D Oh cum on :3 how many account you have O.o
Ο Χάρος Posted September 4, 2017 Author 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 Ο Χάρος
vampir Posted September 17, 2017 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.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now