briot / geneapro

Genealogical software based on the GenTech data model
http://briot.github.com/geneapro/
GNU General Public License v2.0
33 stars 8 forks source link

Change code to use f-strings throughout. Made to_json quoting consist… #50

Closed changeling closed 5 years ago

changeling commented 5 years ago

…ent.

Changed to f-string formatting throughout for readability and performance. Changed a few instances of single-quoting ' to double-quotes " in to_json returns.

changeling commented 5 years ago

On a side-note, in addition to readability advantages, f-strings turn out to be significantly better for performance. Out of curiosity, I benchmarked the various string-representation approaches, and f-strings are a clear winner. In the following, 'simple' refers to a bare string without any expressions, and the rest should be self-explanatory. I used timeit and ran 1,000,000 iterations last night, with the default seconds for time unit:

simple f-string:               144.56685653899999
simple string:                 128.51768768099998
f-string expressions:          414.141036833
printf style:                  655.51534457
concatentaion:                 804.0907651130001
.format() style:               874.8606495869999
using Template():              6838.884037724

Note that in this PR, I've avoided converting 'simple' string statements, though the difference in performance is negligible.

briot commented 5 years ago

Interesting data. I'll review your patch shortly, but I have some pending changes I'd like to finish first