AX2009里调用.NET DLL的效率问题

经常在AX2009里引用.NET的DLL,因为序列化和反序列化,用.NET的定义的实体方便一些,平时数据量不大,也没觉得有什么问题,今天要把几万条数据从数据库中取出来序列化以后,调用第三方系统的接口,发现很慢,开始以为是从数据库里取数慢,于是优化索引,发现没有任何改善。后来把.NET实体调用部分去掉,很快就完成了。

于是在.NET里用C#写了一段代码做测试

DateTime startTime = DateTime.Now;
            POSHelper.POS.GoodsBarcodeList barcodeList = new POSHelper.POS.GoodsBarcodeList();
            for (int i = 0; i <= 100000; i++)
            {
                POSHelper.POS.GoodsBarcode barcode = new POSHelper.POS.GoodsBarcode();
                barcode.Barcode = "111111";
                barcode.CName = "111111";
                barcode.Code = "111111";
                barcode.EAMU = "111111";
                barcodeList.Add(barcode);
            }
            DateTime endTime = DateTime.Now;
            MessageBox.Show((endTime - startTime).TotalMilliseconds.ToString());

上面这一段代码执行只要20-100毫秒的样子,正常范围。

在X++里写一段等效的代码

POSHelper.POS.GoodsBarcodeList          goodsBarcodeList;
    POSHelper.POS.GoodsBarcode              goodsBarcode;
    System.DateTime                         startTime,endTime;
    System.TimeSpan                         timeSpan;
    int                                     i;
    ;

    new InteropPermission(InteropKind::ClrInterop).assert();

    goodsBarcodeList = new POSHelper.POS.GoodsBarcodeList();
    startTime = System.DateTime::get_Now();
    goodsBarcodeList = new POSHelper.POS.GoodsBarcodeList();

    for(i=1;i<=100000;i++)
    {
        goodsBarcode = new POSHelper.POS.GoodsBarcode();
        goodsBarcode.set_Barcode("1111111");
        goodsBarcode.set_CName("1111111");
        goodsBarcode.set_Code("1111111");
        goodsBarcode.set_EAMU("1111111");
        goodsBarcodeList.Add(goodsBarcode);
    }
    endTime = System.DateTime::get_Now();
    CodeAccessPermission::revertAssert();
    timeSpan = System.DateTime::op_Subtraction(endTime,startTime);
    
    print timeSpan.get_TotalMilliseconds();
    pause;

用了38290毫秒,也就是整整用了38S,搞不懂它在思考什么。
在AX2009里调用.NET类库的效率是让人崩溃的,偶尔数据量小不频繁调用的代码,用用的确蛮方便的,要是数据量大,考虑效率的情况下,还是换个方式吧。。。

转载于:https://www.cnblogs.com/Farseer1215/p/7841410.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值