image-random

Benchmark created by tzumin on


Preparation HTML

<html>
  <head>
  </head>
  <body>
    <script>
var boxElement = document.createElement('div');
var imgElement = document.createElement('img');
var viewWidth = window.innerWidth;
var viewHeight = window.innerHeight;
var baseSize = 300;
var imgAssignArr = [];
var imgAssignFlagArr = [];
var showImgIndex = 0;
var init = function () {
  boxElement.id = "box";
  baseSize = Math.floor(viewWidth / 4);
  if (viewWidth * 0.75 > viewHeight) {
      baseSize = Math.floor(viewHeight / 3);
  }
  assignImg();
  mobileHandle();
  boxElement.style.width = baseSize * 4;
  boxElement.style.height = baseSize * 3;
  boxElement.style.backgroundColor = "#eee";
  boxElement.style.margin = "auto";
  document.body.appendChild(boxElement);

}
var assignImg = function () {
  for(var i = 11; i >= 0 ; i--) {
    var index = random();
    imgAssignArr.push({
      x: baseSize * (index % 4),
      y: baseSize * Math.floor(index / 4)
    })
  }
  setTimeout(addImg, 1000);
}
var random = function () {
  var randomNum = Math.floor(Math.random() * 12);
  while(imgAssignFlagArr[randomNum] !== undefined) {
    randomNum = Math.floor(Math.random() * 12);
  }
  imgAssignFlagArr[randomNum] = true;
  return randomNum;
}
var addImg = function () {
  var newImg = imgElement.cloneNode();
  newImg.width = baseSize;
  newImg.height = baseSize;
  newImg.style.position = "absolute";
  newImg.src = "images/" + showImgIndex + ".png";
  newImg.style.marginLeft = imgAssignArr[showImgIndex].x;
  newImg.style.marginTop = imgAssignArr[showImgIndex].y;
  boxElement.appendChild(newImg);
  showImgIndex = showImgIndex + 1;
  if (showImgIndex < 12) {
    setTimeout(addImg, 1000);
  }
}
var mobileHandle = function () {
  console.log('modileHandler');
  window.addEventListener("orientationchange", function() {
    alert("the orientation of the device is now " + screen.orientation);
  });
}
init();
</script>
  </body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
test
test
ready
test1
test1
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by tzumin on