parsing - improve the exception handling vb.net -
i have small trouble performance of exception handling. i'm building... aaaaa... soooo...hmmm...a graph db? yeah this... vb.net. i'm building parser, handling basic functions of db(?) happen? user makes research, program tab them, , allow make computation . string handling, but, give complete instrument, implement mathematical functions.
there no way know developing-time math kind of value going insert. , especially, there no way know if each row of column comes out traversal has same data type. schema-free db(?). happen...i have implement error handling.
integer = 0 pr.r.wsrowcount - 1 try pr.r.wsitem(cix, i) = convert.todouble(pr.r.wsitem(ca.ix, i)) * convert.todouble(pr.r.wsitem(cb.ix, i)) catch pr.r.wsitem(cix, i) = string.empty end try next
something this... (psss.. convert.todouble()
performant function between cdbl()
, double.parse()
etc). when run it, if rows (benchmark around 2000 rows), numeric... few milliseconds, if rows not numeric, require 3 or 4 seconds. , worst scenario, if user should mathematical operation in string column... goodbye, meanwhile better go take coffee. computer may not advanced in world, aware if there way avoid incredible delay in error handling? remember parser of query , avoid make heavy.
you using exceptions fix problem when code encounter value cannot converted double. called driving code using exceptions , bad practice. catching exceptions never fix scenario.
in particular when there clear way avoid them
integer = 0 pr.r.wsrowcount - 1 dim d1 double dim d2 double if double.tryparse(pr.r.wsitem(ca.ix, i), d1) if double.tryparse(pr.r.wsitem(cb.ix, i), d2 pr.r.wsitem(cix, i) = (d1 * d2).tostring() else pr.r.wsitem(cix, i) = string.empty end if else pr.r.wsitem(cix, i) = string.empty end if next
convert.todouble
cannot handle fact string not valid numeric value , if encounter case throws exception. throwing exception costly in terms of perfomance in particular gathering information call stack.
instead, if there possibility input contains values cannot converted double, double.tryparse
correct way proceed if benchmarks show little difference in performance. double.tryparse
doesn't raise exception if string passed cannot converted double, return false. in way costly exception avoided , have more predictable time of execution
said that, should reevaluate approach store every kind of data in string structure. need of constant conversion between string , intended data type real bottleneck here.
Comments
Post a Comment