MongoDB Java API: put() vs append() -
i new mongodb , going through tutorial java & mongodb. notice there put() , append() basicdbobject , took @ api, put() inherit , append() built-in basicdbobject. different, such speed of access? thanks!
from basicdbobject sources:
public basicdbobject append( string key , object val ){ put( key , val ); return this; } put() returns previous value, if applicable. append() calls put() internally , returns basicdbobject instance itself. essentially, append() more fluent interface put(). allows this:
basicdbobject o = new basicdbobject().append("one", 1).append("two", 2).append("three", 3); as far performance goes, jvm supposedly inline methods append() if used enough somewhere. experience , quite bit of profiling, however, not true , bound gain little bit of speed using put() directly , saving jvm guesswork.
that said, code readability should priority. write code feel comfortable, , benchmark/profile afterwards find possible optimizations. premature optimization temptation should avoided @ costs...
Comments
Post a Comment