Skip to content

Instantly share code, notes, and snippets.

@fabriziogiordano
Created June 2, 2011 23:26
Show Gist options
  • Save fabriziogiordano/1005567 to your computer and use it in GitHub Desktop.
Save fabriziogiordano/1005567 to your computer and use it in GitHub Desktop.
Javascript Math Floor vs. Bitwise operator
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>[Javascript] Math floor and bitwise operator</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<p id="result"> </p>
</body>
</html>
var a = [];
var time = new Date().getTime();
var result = document.getElementById('result');
for( i = 0; i < 1000; i++ ) {
//result.innerHTML += '<br/>' + (Math.random() * 100000 | 0);
result.innerHTML += '<br/>' + Math.floor( Math.random() * 100000 );
}
var elapsed = new Date().getTime() - time;
alert( "elapsed time: " + elapsed );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment