当前位置:网站首页>Performance of calling delegates vs methods
Performance of calling delegates vs methods
2022-07-05 03:03:00 【fyin1314】
problem :
Following this question - Pass Method as Parameter using C# and some of my personal experience I'd like to know a little more about the performance of calling a delegate vs just calling a method in C#. The next question - Use C# Pass the method as an argument , And some of my personal experience , I want to know more about the performance of invoking delegates rather than just using C# Performance of calling methods .
Although delegates are extremely convenient, I had an app that did lots of callbacks via delegates and when we rewrote this to use callback interfaces we got an order of magnitude speed improvement. Although delegation is very convenient , But I have an application that makes many callbacks through delegates , When we rewrite the program to use the callback interface , The speed has been improved .This was with .NET 2.0 so I'm not sure how things have changed with 3 and 4. This is a .NET 2.0 Version of , So I'm not sure 3 and 4 The change of .
How are calls to delegates handled internally in the compiler/CLR and how does this affect performance of method calls? How to use the compiler / CLR Internal processing calls to delegates , How does this affect the performance of method calls ?
EDIT - To clarify what I mean by delegates vs callback interfaces. edit - To clarify, I mean delegate and callback interfaces .
For asynchronous calls my class could provide an OnComplete event and associated delegate which the caller could subscribe to. For asynchronous calls , My class can provide OnComplete Events and associated delegates that the caller can subscribe to .
Alternatively I could create an ICallback interface with an OnComplete method that the caller implements and then registers itself with the class that will then call that method on completion (ie the way Java handles these things). perhaps , I can implement it with the caller OnComplete Method to create a ICallback Interface , Then register yourself with this class , This class will call this method when it is finished ( namely Java The way to deal with these things ).
Solution :
Reference resources : https://stackoom.com/en/question/8joV边栏推荐
- Cut! 39 year old Ali P9, saved 150million
- Ubantu disk expansion (VMware)
- Character painting, I use characters to draw a Bing Dwen Dwen
- 【LeetCode】98. Verify the binary search tree (2 brushes of wrong questions)
- Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time
- Design and implementation of community hospital information system
- Pat class a 1162 postfix expression
- [micro service SCG] 33 usages of filters
- Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
- Machine learning experiment report 1 - linear model, decision tree, neural network part
猜你喜欢
Azkaban installation and deployment
【LeetCode】501. Mode in binary search tree (2 wrong questions)
Why are there fewer and fewer good products produced by big Internet companies such as Tencent and Alibaba?
1. Five layer network model
SQL injection exercise -- sqli Labs
2021 Li Hongyi machine learning (2): pytorch
Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
1.五层网络模型
【LeetCode】110. Balanced binary tree (2 brushes of wrong questions)
随机推荐
Breaking the information cocoon - my method of actively obtaining information - 3
2. Common request methods
Tencent cloud, realize image upload
Daily question 2 12
Structure of ViewModel
Azkaban installation and deployment
Asp+access campus network goods trading platform
There is a question about whether the parallelism can be set for Flink SQL CDC. If the parallelism is greater than 1, will there be a sequence problem?
单项框 复选框
Design and implementation of campus epidemic prevention and control system based on SSM
SFTP cannot connect to the server # yyds dry goods inventory #
[Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
SQL performance optimization skills
ASP. Net core 6 framework unveiling example demonstration [01]: initial programming experience
Design and implementation of kindergarten management system
Tiny series rendering tutorial
Anchor free series network yolox source code line by line explanation four (a total of ten, ensure line by line explanation, after reading, you can change the network at will, not just as a participan
数据库和充值都没有了
Hmi-30- [motion mode] the module on the right side of the instrument starts to write
Multi person online anonymous chat room / private chat room source code / support the creation of multiple chat rooms at the same time