当前位置:网站首页>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边栏推荐
- Day_ 17 IO stream file class
- 有個疑問 flink sql cdc 的話可以設置並行度麼, 並行度大於1會有順序問題吧?
- 【微服务|SCG】Filters的33种用法
- 问下,这个ADB mysql支持sqlserver吗?
- 【LeetCode】222. The number of nodes of a complete binary tree (2 mistakes)
- ELFK部署
- 端口,域名,协议。
- When the low alcohol race track enters the reshuffle period, how can the new brand break the three major problems?
- 1. Five layer network model
- Kuboard
猜你喜欢
Devtools的簡單使用
Kbp206-asemi rectifier bridge kbp206
Scientific research: are women better than men?
【LeetCode】501. Mode in binary search tree (2 wrong questions)
Bumblebee: build, deliver, and run ebpf programs smoothly like silk
Hot knowledge of multithreading (I): introduction to ThreadLocal and underlying principles
问题解决:AttributeError: ‘NoneType‘ object has no attribute ‘append‘
Azkaban实战
Yuan universe also "real estate"? Multiple second-hand trading websites block metauniverse keywords
Design and implementation of kindergarten management system
随机推荐
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 1)
Watch the online press conference of tdengine community heroes and listen to TD hero talk about the legend of developers
Ask, does this ADB MySQL support sqlserver?
Yyds dry goods inventory intelligent fan based on CC2530 design
El select, El option drop-down selection box
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
Pytest (4) - test case execution sequence
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
Usage scenarios and solutions of ledger sharing
SQL performance optimization skills
Linux安装Redis
Pat class a 1162 postfix expression
Character painting, I use characters to draw a Bing Dwen Dwen
Azkaban安装部署
Last words record
FBO and RBO disappeared in webgpu
Apache build web host
2021 Li Hongyi machine learning (1): basic concepts
Idea inheritance relationship