⬆️ ⬇️

How much optimization or “free breakfast does not happen”

Today's software engineering word is "farpotshket." This is a Yiddish word meaning,

(c) Andr Zerozero


We poured here the other day at work on the question "Would it be good to cache a regular season" in a completely banal



uncached = function(data_in) { return /_(\d)+(?:#(\d)+)?$/.exec(data_in); }; 


by doing something like that



  cached = (function() { var pattern = /_(\d)+(?:#(\d)+)?$/; return function(data_in) { return pattern.exec(data_in); }; })(); 


The idea is popular, but how many people thought about real profit and overhead costs?



The results of benchmarking tests turned out to be strange - contrary to my expectations, and the difference was within the measurement error:

')

 uncached 13,268
 cached 13,070


Although there may be numbers on a platform browser link and they will be valid, but what does it cost?



We take the complexity-report and look at the indicators of our functions, respectively:



 Function: uncached
     Physical SLOC: 3
     Logical SLOC: 1
     Parameter count: 1
     Cyclomatic complexity: 1
     Halstead difficulty: 2
     Halstead volume: 18.094737505048094
     Halstead effort: 36.18947501009619

 Function: cached
     Physical SLOC: 8
     Logical SLOC: 3
     Parameter count: 0
     Cyclomatic complexity: 1
     Halstead difficulty: 2.6666666666666665
     Halstead volume: 22.458839376460833
     Halstead effort: 59.89023833722889


Absolute numbers are small, but still pay attention to the indicators of the code by Halstead - 30% increase in difficulty and 65% increase in effort with close to zero profit - a good hint that something went wrong.



Yes, there are good practices and excellent tips, but you need to use them wisely, critically evaluating and not pulling them out of context.

And do not engage in preliminary optimization - first profiling and only then improvements.



In short - do not make bullshit.

Source: https://habr.com/ru/post/179267/



All Articles