常常在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++裏寫一段等效的代碼spa
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類庫的效率是讓人崩潰的,偶爾數據量小不頻繁調用的代碼,用用的確蠻方便的,要是數據量大,考慮效率的狀況下,仍是換個方式吧。。。code