早期绑定有哪些(缺点)优势? [英] What are the (dis)advantages of early bound?

查看:79
本文介绍了早期绑定有哪些(缺点)优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究CRM中早期绑定和后期绑定的优缺点.我对这个主题有个好主意,但有些地方我不清楚.

I'm researching the pros and cons of early and late binding in CRM. I've got a good idea on the subject but there are some points I'm unclear about.

  1. 有人说提早出价是最快的,其他则是迟到的.有什么明显的区别吗?

  1. Some say that early biding is the fastest, other that lates is. Is there any significant difference?

一个如何处理自定义实体的早期绑定?

How does one handle early binding for custom entities?

一个人如何处理具有自定义字段的默认实体的早期绑定?

How does one handle early binding for default entities with custom fields?

有很多链接,但是最有用的是那些链接.还有其他指针吗?

There is a lot of links but the most useful I got my mouse on were those. Any other pointers?

两者都
早点购买
迟到了

Pro both
Pro early
Pro late

推荐答案

  1. 有人说提早出价是最快的,而其他则迟到.有什么明显的区别吗?

  1. Some say that early biding is the fastest, other that late is. Is there any significant difference?

a.由于Early bound只是晚期绑定实体类的包装,并且包含其中的所有功能,因此它的运行时间不会比Latebound更快.但是,这种差异非常小,我与 Eric Lippert的区别是问题.速度上不可忽略的一个差异是开发速度.早期绑定对于开发来说要快得多,而恕我直言的错误要少得多.

a. Since Early bound is just a wrapper over the late bound entity class, and contains all the functionality there of, it can't have a faster runtime than late bound. But, this difference is extremely small and I differ to Eric Lippert in the What's Fastest type of questions. The one difference in speed that isn't negligible, is the speed of development though. Early bound is much faster for development, and much less error prone IMHO.

一个如何处理自定义实体的早期绑定?

How does one handle early binding for custom entities?

a. CrmSrvcUtil为自定义实体生成早期绑定类,就像默认工具(我创建了此工具使生成类更加容易.更新 :此后它已移至 GitHub 更新2 现在位于XrmToolBox插件存储中,搜索"Early Bound Generator").每次对CRM实体进行更改时,都需要更新实体类型定义(仅当您要使用新的属性或实体,或者您已删除当前使用的属性或实体时.可以使用只要您不设置任何实际不存在的属性的值,过期的早期绑定实体类(这与后期绑定的确切要求相同)

a. The CrmSrvcUtil generates the early bound classes for custom entities, exactly like the default ones (I created this tool to make generating the classes even easier. Update: It has since moved over to GitHub Update 2 It is now in the XrmToolBox Plugin Store, search for "Early Bound Generator" ). Each time a change is made to a CRM entity, the entity type definitions will need to be updated (only if you want to use a new property or entity, or you've removed a property or entity that you currently use. You can use early bound entity classes that are out of date, as long as you don't set the values of any properties that don't actually exist, which is the same exact requirements of late bound)

一个如何处理具有自定义字段的默认实体的早期绑定?

How does one handle early binding for default entities with custom fields?

a.请参阅问题2的答案.

a. See the answer to question 2.

使用早期绑定实体时,一个小问题是需要在IOrganizationService中启用早期绑定代理类型.对于OrganizationServiceProxy来说这很容易,但是对于插件,尤其是自定义工作流程活动,可能需要采取更多步骤.

One of the little gottcha's when working with early bound entities, is the need to enable early bound proxy types in your IOrganizationService. This is easy for the OrganizationServiceProxy, but may take a few more steps for plugins and especially custom workflow activities.

下面是我的代码,正在相当不活跃的本地开发环境下进行测试.随时为您自己测试

Below is my code, testing against a pretty inactive local dev environment. Feel free to test for youself

using (var service = TestBase.GetOrganizationServiceProxy())
{
    var earlyWatch = new Stopwatch();
    var lateWatch = new Stopwatch();

    for (int i = 0; i < 100; i++)
    {
        earlyWatch.Start();
        var e = new Contact() { FirstName = "Early", LastName = "BoundTest"
        e.Id = service.Create(e);
        earlyWatch.Stop();

        lateWatch.Start();
        var l = new Entity();
        l.LogicalName = "contact";
        l["firstname"] = "Late";
        l["lastname"] = "BoundTest";
        l.Id = service.Create(l);
        lateWatch.Stop();

        service.Delete(e);
        service.Delete(l);
    }

    var earlyTime = earlyWatch.ElapsedMilliseconds;
    var lateTime = lateWatch.ElapsedMilliseconds;
    var percent = earlyWatch.ElapsedTicks / (double)lateWatch.ElapsedTicks;

}

我的两个测试结果(请注意,运行两个测试在统计上并不显着,无法得出任何统计结论,但是我认为它们可以帮助我们证明其并不是真正的性能下降,不足以证明某些开发成果是合理的) )与本地开发环境相抵触,几乎没有其他活动可以破坏测试.

My two test results (please note that running two test are not statistically significant to draw any sort of statistical conclusion, but I think they lend weight to it not really being that big of a performance decrease to justify some of the development gains) where ran against a local dev environment with very little other activity to disrupt the tests.

Number Creates  |   Early (MS)  |   Late (MS)   |   % diff (from ticks)
10              |   1242        |   1106        |   12.3%
100             |   8035        |   7960        |   .1% 

现在,让我们插入数字以查看区别. 12%似乎很多,但其中12%是什么?实际的差异是.136秒.假设您每分钟创建10个Contacts .... 136 x 60分钟/小时x 24小时/天= 195.84 s/天,或一天大约3秒.假设您花了3个开发人员小时来尝试找出哪个更快.为了使程序能够节省那么多时间,需要60天的24/7 10分钟/分钟的处理时间,以便更快的代码偿还" 3个小时的决策时间.

Now lets plug in the numbers and see the difference. 12% seems like a lot, but 12% of what? The actual difference was .136 seconds. Let's say you create 10 Contacts every minute... .136 x 60 min / hour x 24 hours / day = 195.84 s/day or about 3 seconds a day. Lets say you spend 3 developer hours attempting to figure out which is faster. In order for the program to be able to save that much time, it would take 60 days of 24/7 10 contacts / minute processing in order for the faster code to "pay back" it's 3 hours of decision making.

因此,规则是,始终选择比起更快的方法更具可读性/可维护性的方法.如果性能不够快,请考虑其他可能性.但是在100的98倍中,它实际上不会以最终用户可以检测到的方式影响性能.

So the rule is, always pick the method that is more readable/maintainable than what is faster first. And if the performance isn't fast enough, then look at other possibilities. But 98 times out of 100, it really isn't going to affect performance in a way that is detectable by an end user.

过早的优化是万恶之源-DonaldKnuth

Premature optimization is the root of all evil -- DonaldKnuth

这篇关于早期绑定有哪些(缺点)优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆