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

  • 相关阅读:
    .net core3.1 abp动态菜单和动态权限(思路) (二)
    .net core3.1 abp学习开始(一)
    api.versioning 版本控制 自动识别最高版本
    .netcore 定制化项目开发的思考和实现
    netcore 非注入全局获取配置文件
    linux nginx搭建与使用
    linux docker .net core 从建立网站到预览
    linux 学习 mysql安装到连接
    linux 安装redis及问题收集
    为何说要多用组合少用继承?如何决定该用组合还是继承?
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/7841410.html
Copyright © 2011-2022 走看看