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