optimize speed calculate