Skip to content

Instantly share code, notes, and snippets.

@ztirom
Created November 30, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztirom/84de025d34c7bc69757bc47b79680bb8 to your computer and use it in GitHub Desktop.
Save ztirom/84de025d34c7bc69757bc47b79680bb8 to your computer and use it in GitHub Desktop.
AX Insert vs RecordInsertList Full
class BulkInsert
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
int timerStart, timerEnd;
str timeConsumed;
int rows;
BulkInsertTable bulkInsertTable;
for (rows = 10000; rows <= 1000000; rows = rows * 10)
{
// delete all records
delete_from bulkInsertTable;
// insert
timerStart = timeNow();
ttsbegin;
BulkInsert::insert(rows);
ttscommit;
timerEnd = timeNow();
timeConsumed = timeConsumed(timerStart, timerEnd);
info(strFmt("INSERT: Added %1 rows in %2 seconds", rows, timeConsumed));
// delete all records
delete_from bulkInsertTable;
// insert with a list
timerStart = timeNow();
ttsbegin;
BulkInsert::insertWithList(rows);
ttscommit;
timerEnd = timeNow();
timeConsumed = timeConsumed(timerStart, timerEnd);
info(strFmt("LIST: Added %1 rows in %2 seconds", rows, timeConsumed));
}
}
// good old insert
public static void insert(int rows)
{
BulkInsertTable bulkInsertTable;
for (var i = 0; i < rows; i++)
{
bulkInsertTable.Id = i;
bulkInsertTable.StringValue = strFmt("Value - %1", i);
bulkInsertTable.insert();
}
}
// insert a list of records
public static void insertWithList(int rows)
{
BulkInsertTable bulkInsertTable;
RecordInsertList insertList = new RecordInsertList(bulkInsertTable.TableId);
for (var i = 0; i < rows; i++)
{
bulkInsertTable.Id = i;
bulkInsertTable.StringValue = strFmt("Value - %1", i);
insertList.add(bulkInsertTable);
}
insertList.insertDatabase();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment