当前位置:网站首页>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边栏推荐
- Pytest (4) - test case execution sequence
- Eight days of learning C language - while loop (embedded) (single chip microcomputer)
- 【LeetCode】110. Balanced binary tree (2 brushes of wrong questions)
- Design and implementation of community hospital information system
- Flume configuration 4 - customize mysqlsource
- Moco V2 literature research [self supervised learning]
- Kbp206-asemi rectifier bridge kbp206
- Azkaban overview
- [Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
- 【LeetCode】501. Mode in binary search tree (2 wrong questions)
猜你喜欢
this+闭包+作用域 面试题
单项框 复选框
Sqoop command
qrcode:将文本生成二维码
2. Common request methods
Linux Installation redis
【LeetCode】111. Minimum depth of binary tree (2 brushes of wrong questions)
[2022 repair version] community scanning code into group activity code to drain the complete operation source code / connect the contract free payment interface / promote the normal binding of subordi
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
随机推荐
2021 Li Hongyi machine learning (3): what if neural network training fails
How to make OS X read bash_ Profile instead of Profile file - how to make OS X to read bash_ profile not . profile file
this+闭包+作用域 面试题
Six stone programming: advantages of automated testing
[Yu Yue education] National Open University autumn 2018 8109-22t (1) monetary and banking reference questions
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
1. Five layer network model
Tiny series rendering tutorial
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
SFTP cannot connect to the server # yyds dry goods inventory #
IPv6 experiment
tuple and point
Comparison of advantages and disadvantages between platform entry and independent deployment
Character painting, I use characters to draw a Bing Dwen Dwen
Design and practice of kubernetes cluster and application monitoring scheme
Asemi rectifier bridge 2w10 parameters, 2w10 specifications, 2w10 characteristics
How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?
Clean up PHP session files
This + closure + scope interview question
Design and implementation of high availability website architecture