Skip to content

Instantly share code, notes, and snippets.

@YuriyZaletskyy
Last active November 27, 2018 17:28
Show Gist options
  • Save YuriyZaletskyy/726d909c824249556f2584ba0137df7a to your computer and use it in GitHub Desktop.
Save YuriyZaletskyy/726d909c824249556f2584ba0137df7a to your computer and use it in GitHub Desktop.
Test of performance on MS SQL and MySQL
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PX.Data;
using PX.Objects.SO;
namespace SalesOrdersTest
{
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> Test;
[PXProcessButton]
[PXUIField(DisplayName = "Test", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
public virtual IEnumerable test(PXAdapter adapter)
{
PXLongOperation.StartOperation( Base, ()=>
{
var graph = PXGraph.CreateInstance<SOOrderEntry>();
CreateSalesOrders(graph);
});
return adapter.Get();
}
private const int smallTest = 10;
private const int mediumTest = 100;
private const int bigTest = 500;
private const int bigerTest = 1000;
private const int bigerTest2 = 1500;
public static void CreateSalesOrders(SOOrderEntry graph)
{
StringBuilder sb = new StringBuilder();
var sw = new Stopwatch();
ExecuteSOCreationInCycle(graph, sw, sb, smallTest);
ExecuteSOCreationInCycle(graph, sw, sb, mediumTest);
ExecuteSOCreationInCycle(graph, sw, sb, bigTest);
ExecuteSOCreationInCycle(graph, sw, sb, bigerTest);
ExecuteSOCreationInCycle(graph, sw, sb, bigerTest2);
using (StreamWriter file =
new StreamWriter(@"c:\Acumatica\results.txt"))
{
file.Write(sb.ToString());
}
}
private static void ExecuteSOCreationInCycle(SOOrderEntry graph, Stopwatch sw, StringBuilder log, int numberOfCycles)
{
sw.Start();
for (int i = 0; i < numberOfCycles; i++)
{
CreateSO(graph);
}
sw.Stop();
log.Append($"{numberOfCycles} Sales orders = {sw.ElapsedMilliseconds} milliseconds\r\n");
}
private static void CreateSO(SOOrderEntry graph)
{
try
{
graph.Clear();
var newSoOrder = graph.Document.Insert();
graph.Document.SetValueExt<SOOrder.customerID>(graph.Document.Current, 4901);
graph.Document.SetValueExt<SOOrder.status>(graph.Document.Current, "N");
graph.Document.Update(newSoOrder);
var transaction = graph.Transactions.Insert();
graph.Transactions.SetValueExt<SOLine.inventoryID>(transaction, 456);
graph.Transactions.SetValueExt<SOLine.orderQty>(transaction, 5.0m);
graph.Transactions.SetValueExt<SOLine.curyUnitPrice>(transaction, 6.0m);
graph.Transactions.Update(transaction);
graph.Persist();
}
catch (Exception ex)
{
PXTrace.WriteError(ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment