Источник:
http://sysdictcoder.com/blog/x-method-call-performance/
==============
Microsoft’s recommendations for
performance optimizations are interesting:
- Calls between tiers (client/server) are slow.
- Method calls are expensive. Try to reduce the number of calls. For example, don’t call the same method several times if you can store a value from the method and instead use that value.
These statements are probably true but as with all good advice it is important to know the context in which it makes sense. How slow is slow and how expensive is expensive? And should you worry about it? Let’s find out.
Test cases
In X++ there are different kinds of methods and different ways to call them. There are some interesting cases I can think of right away.
- Static versus instance methods
- Staying on the same tier versus calling methods across tiers
- Calling a method on an object of a supertype (Object) instead of the exact subtype
- Calling a method through reflection (SysDict* classes)
Test setup
Methods calls may be slow, but they’re certainly not slow enough to accurately measure the time of a single call. Repeating the exact same call a large number of times should average out any measurement errors.
The timing code is basically this:
<div class="wp_syntax"><div class="code"> timer.
start(1);
for (i=
1; i