Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code redundancy making it faster?

EDIT: Seems to have disappeared.

I've benchmarked some parts of my code and found out that if its like this:

if(oneCondition)  
{
   performOne();
   performOne_two();

   abc();
   def();
   gh();
} else
{
   performTwo();
   performTwo_two();

   abc();
   def();
   gh();
}

it runs significantly faster than if its like this:

if(oneCondition)  
{
   performOne();
   performOne_two();
} else
{
   performTwo();
   performTwo_two();
}

abc();
def();
gh();

(In relation: the first version takes around 585ms while the second version takes around 610-630ms).

Can someone explain me why?

This is the code part: (Its part of a backpropagation algorithm for a neural network)

https://pastebin.com/9WfEJdPt // I have moved on

like image 476
Fabian Schneider Avatar asked Apr 27 '26 12:04

Fabian Schneider


1 Answers

The linked code uses the same functions with a different data feed/argument. Your JIT apparently found a way to optimise at least one of the common functions for at least one of those matrix types. Most likely you have either pExpectedOutput or this.weightMatrixes[layerNr + 1] hardcoded. Ideally the JIT should be able to make this distinction by itself, eliminating the need for redundant code.

like image 175
Pascal de Kloe Avatar answered Apr 30 '26 01:04

Pascal de Kloe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!