forked from konvajs/konva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhit-ratio.html
70 lines (61 loc) · 1.58 KB
/
hit-ratio.html
1
2
3
4
5
6
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
canvas {
border: 1px solid #9C9898;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="../../dist/konva-dev.js"></script>
<script>
var stage = new Konva.Stage({
container: 'container',
width: 500,
height: 250
});
var layer = new Konva.Layer();
for(var j =0; j < 20; j++) {
layer.add(new Konva.Circle({
x : stage.width() * Math.random(),
y : stage.height() * Math.random(),
radius : 50,
stroke : 'black',
fill : Konva.Util.getRandomColor(),
strokeWidth : 5,
draggable : true
}));
}
stage.add(layer);
var i, count = 500, start;
var start = Date.now();
for(i = 0; i< count; i++) {
layer.draw();
}
var defTime = Date.now() - start;
layer.getHitCanvas().setPixelRatio(1);
// layer.getCanvas().setPixelRatio(1);
layer.draw();
start = Date.now();
for(i = 0; i< count; i++) {
layer.draw();
}
var time1 = Date.now() - start;
layer.getHitCanvas().setPixelRatio(0.2);
// layer.getCanvas().setPixelRatio(0.5);
layer.draw();
start = Date.now();
for(i = 0; i< count; i++) {
layer.draw();
}
var time05 = Date.now() - start;
alert('def ' + defTime + ', 1 ration ' + time1 + ', 05 ration ' + time05)
</script>
</body>
</html>