Created
November 30, 2018 11:28
-
-
Save ztirom/84de025d34c7bc69757bc47b79680bb8 to your computer and use it in GitHub Desktop.
AX Insert vs RecordInsertList Full
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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