most fit proceed check dbnull following distribute variable?
this doubt comes adult occasionally, nonetheless i haven't seen tolerable answer.
a customary settlement (row datarow):
(row["value"] != dbnull.value)
{
someobject.member = row["value"];
}
my initial doubt some-more fit (i've flipped condition):
row["value"] == dbnull.value; // or
row["value"] dbnull; // or
row["value"].gettype() == typeof(dbnull) // or... any suggestions?
indicates .gettype() should faster, nonetheless maybe compiler knows few tricks i don't?
second question, value caching value row["value"] does compiler optimize indexer divided anyway?
for example:
vigilant valueholder;
(dbnull.value == (valueholder = row["value"])) {}
notes:
- row["value"] exists.
- i don't know buttress index buttress (hence buttress name lookup).
- i'm seeking personally checking dbnull following assignment (not beforehand optimization, etc.).
i benchmarked few scenarios (time seconds, 10,000,000 trials):
row["value"] == dbnull.value: 00:00:01.5478995
row["value"] dbnull: 00:00:01.6306578
row["value"].gettype() == typeof(dbnull): 00:00:02.0138757
object.referenceequals same opening "=="
the many engaging result? mismatch name buttress box (for example, "value" instead "value", takes roughly 10 times longer (for string):
row["value"] == dbnull.value: 00:00:12.2792374
the cool story seems can't feeling adult buttress the index, following pledge buttress name feed indexer matches datacolumn's name exactly.
caching value also appears perceptibly twice fast:
no caching: 00:00:03.0996622
with caching: 00:00:01.5659920
so many fit slight seems be:
vigilant temp;
twine variable;
(dbnull.value != (temp = row["value"]))
{
non-static = temp.tostring();
}
Comments
Post a Comment