Multiply directly instead of using pow ($number, 2);
This small optimization allows us to improve from: OLD php: 0.012100038051605 Sec. New native: 0.0096198790073395 Sec. (This is already 20 percent faster) ..to: OLD php: 0.012276937961578 Sec. New native: 0.0022540950775146 Sec. What is 80 percent faster than our PHP class.
This commit is contained in:
@@ -39,7 +39,7 @@ PHP_FUNCTION(dlib_vector_length)
|
||||
elem_x = zend_hash_index_find(Z_ARRVAL_P(x_arg), i);
|
||||
elem_y = zend_hash_index_find(Z_ARRVAL_P(y_arg), i);
|
||||
|
||||
sum += pow(Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y), 2);
|
||||
sum += (Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y))*(Z_DVAL_P(elem_x) - Z_DVAL_P(elem_y));
|
||||
}
|
||||
|
||||
RETURN_DOUBLE(sqrt(sum));
|
||||
|
||||
Reference in New Issue
Block a user