switch to js and improve measurement accuracy