java - Hardcoding values vs. reading from file -
this general question efficiency of hardcoding data - i'm writing program in java chemical analysis, , need use isotopic abundances of different elements. way have set right values (which never need modified) stored final fields in class, i.e.
static final double c12abundance = .989; static final double c12mass = 12;
a lot of similar programs store type of data in xml file, read values there, this:
<compounds> <elements> <element symbol='c' mono_isotopic_mass ='12.00000000000' abundance='.989'/>
is there reason (performance, memory, etc) read way? seems easier leave field.
hard coding way faster in terms of performance , memory allocation.
the thing gain reading file code re-usability (running program different parameters without need recompile it).
note reading file has following steps:
- declare variable use storing value.
- create input (stream) object
- initialize path
- open file fs
- find correct line read from
- read value
- store in variable above
- close input (stream)
that's pretty big overhead instead of having pre-compiled final variable value
Comments
Post a Comment