Update performance is dependent upon the structure and complexity of objects. This is demonstrated in the following test:
UpdatePerformanceBenchmark.cs: RunDifferentObjectsTest
private void RunDifferentObjectsTest()
{
System.Console.WriteLine("Update test with different objects");
int objectsToUpdate = 90;
int updated = objectsToUpdate;
InitDifferentObjectsTest();
Clean();
System.Console.WriteLine(" - primitive object with int field");
Open(Configure());
StoreSimplest();
IObjectSet result = objectContainer.QueryByExample(null);
StartTimer();
for (int i = 0; i < objectsToUpdate; i++)
{
if (result.HasNext())
{
SimplestItem item = (SimplestItem)result.Next();
item._id = 1;
Update(item);
}
else
{
updated = i;
break;
}
}
StopTimer("Updated " + updated + " items");
Close();
Clean();
Open(Configure());
System.Console.WriteLine(" - object with string field");
Store();
updated = objectsToUpdate;
result = objectContainer.QueryByExample(null);
StartTimer();
for (int i = 0; i < objectsToUpdate; i++)
{
if (result.HasNext())
{
Item item = (Item)result.Next();
item._name = "Updated";
Update(item);
}
else
{
updated = i;
break;
}
}
StopTimer("Updated " + updated + " items");
Close();
Clean();
Open(Configure());
System.Console.WriteLine(" - object with StringBuilder field");
StoreWithStringBuilder();
updated = objectsToUpdate;
result = objectContainer.QueryByExample(null);
StartTimer();
for (int i = 0; i < objectsToUpdate; i++)
{
if (result.HasNext())
{
ItemWithStringBuilder item =
(ItemWithStringBuilder)result.Next();
item._name = new StringBuilder("Updated");
Update(item);
}
else
{
updated = i;
break;
}
}
StopTimer("Updated " + updated + " items");
Close();
Clean();
Open(Configure());
System.Console.WriteLine(" - object with int array field");
StoreWithArray();
updated = objectsToUpdate;
result = objectContainer.QueryByExample(null);
StartTimer();
for (int i = 0; i < objectsToUpdate; i++)
{
if (result.HasNext())
{
ItemWithArray item = (ItemWithArray)result.Next();
item._id = new int[] { 1, 2, 3 };
Update(item);
}
else
{
updated = i;
break;
}
}
StopTimer("Updated " + updated + " items");
Close();
Clean();
Open(Configure());
System.Console.WriteLine(" - object with ArrayList field");
StoreWithArrayList();
updated = objectsToUpdate;
result = objectContainer.QueryByExample(null);
StartTimer();
for (int i = 0; i < objectsToUpdate; i++)
{
if (result.HasNext())
{
ItemWithArrayList item = (ItemWithArrayList)result.Next();
item._ids = new ArrayList();
Update(item);
}
else
{
updated = i;
break;
}
}
StopTimer("Updated " + updated + " items");
Close();
}
UpdatePerformanceBenchmark.cs: SimplestItem
public class SimplestItem
{
public int _id;
public SimplestItem _child;
public SimplestItem()
{
}
public SimplestItem(int id, SimplestItem child)
{
_id = id;
_child = child;
}
}
UpdatePerformanceBenchmark.cs: ItemWithStringBuilder
public class ItemWithStringBuilder
{
public StringBuilder _name;
public ItemWithStringBuilder _child;
public ItemWithStringBuilder()
{
}
public ItemWithStringBuilder(StringBuilder name,
ItemWithStringBuilder child)
{
_name = name;
_child = child;
}
}
UpdatePerformanceBenchmark.cs: ItemWithArray
public class ItemWithArray
{
public int[] _id;
public ItemWithArray _child;
public ItemWithArray()
{
}
public ItemWithArray(int[] id, ItemWithArray child)
{
_id = id;
_child = child;
}
}
UpdatePerformanceBenchmark.cs: ItemWithArrayList
public class ItemWithArrayList
{
public ArrayList _ids;
public ItemWithArrayList _child;
public ItemWithArrayList()
{
}
public ItemWithArrayList(ArrayList ids, ItemWithArrayList child)
{
_ids = ids;
_child = child;
}
}
The results:
Update test with different objects
- primitive object with int field
Store 1000 objects: 273ms
Updated 90 items: 185ms
- object with String field
Store 1000 objects: 166ms
Updated 90 items: 158ms
- object with StringBuffer field
Store 1000 objects: 199ms
Updated 90 items: 488ms
- object with int array field
Store 1000 objects: 78ms
Updated 90 items: 134ms
- object with ArrayList field
Store 1000 objects: 191ms
Updated 90 items: 647ms
In general update of a more complex object takes more time, however the exact result depends on the TypeHandler implementation.
Download example code: