zoukankan      html  css  js  c++  java
  • 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类库的效率是让人崩溃的,偶尔数据量小不频繁调用的代码,用用的确蛮方便的,要是数据量大,考虑效率的情况下,还是换个方式吧。。。

  • 相关阅读:
    用OxyPlot在WPF中演示正演磁异常的变化规律
    《暗时间》读书笔记
    [C++]KMP算法实现
    [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
    [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
    [C++]让CPU使用率曲线呈现为正弦曲线(一)
    [C#]中英文字幕合并的小程序
    [C++]Store Credit——Google Code Jam Qualification Round Africa 2010
    [C++]Saving the Universe——Google Code Jam Qualification Round 2008
    [Java]使用队列求解josephus问题
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/7841410.html
Copyright © 2011-2022 走看看