tf1pi.html 760 Bytes
Newer Older
Neil Gershenfeld's avatar
wip  
Neil Gershenfeld committed
1 2 3 4 5
<html>
<body>
<script src=tf.min.js></script>
<script>
//
Neil Gershenfeld's avatar
add 3  
Neil Gershenfeld committed
6
// tf1pi.html
Neil Gershenfeld's avatar
wip  
Neil Gershenfeld committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
// Neil Gershenfeld 11/18/18
// Nikhil Thorat 11/20/18
// TensorFlow.js pi calculation benchmark
// pi = 3.14159265358979323846
//
const points = 1e7
const a = tf.scalar(0.5)
const b = tf.scalar(0.75)
const c = tf.scalar(0.25)

function f() {
  const index = tf.range(1,points)
  return tf.sum(tf.div(a,tf.mul(index.sub(b),index.sub(c)))).dataSync();
}
// Warmup
f();

const tstart = performance.now()/1000
const sum = f();
const tend = performance.now()/1000
const mflops = points*5.0*1e-6/(tend-tstart);
document.write('pi: '+sum.toString())
document.write('<br>')
document.write('time: '+(tend-tstart)+'s')
document.write('<br>')
document.write('estimated MFlops: '+mflops)
</script>