aboutsummaryrefslogtreecommitdiffstats
path: root/speed/event.html
blob: 6d463b4d81d5c1e912edd52f87f599845b65a933 (plain)
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
<!doctype html>
<html>
<head>
	<title>Test Event Handling Performance</title>
	<script src="benchmark.js"></script>
	<script src="jquery-basis.js"></script>
	<script>var old = jQuery.noConflict(true);</script>
	<script src="../dist/jquery.js"></script>
	<script>
	jQuery(function(){
	
	});

	var events = [], num = 400, exec = false;

	jQuery(document).mousemove(function(e){
		if ( exec ) {
			return;
		}

		if ( events.length >= num ) {
			exec = true;
			var s = (new Date).getTime();

			for ( var n = 0; n < 5; n++ ) {
				for ( var i = 0; i < num; i++ ) {
					old.event.handle.call( document, events[i] );
				}
			}

			var oldNum = (new Date).getTime() - s;

			s = (new Date).getTime();

			for ( var n = 0; n < 5; n++ ) {
				for ( var i = 0; i < num; i++ ) {
					jQuery.event.handle.call( document, events[i] );
				}
			}

			var curNum = (new Date).getTime() - s;

			jQuery("#num").text( old.fn.jquery + ": " + oldNum + " " + jQuery.fn.jquery + ": " + curNum );

			jQuery(this).unbind( "mousemove", e.handler );

		} else {
			events.push( e.originalEvent );
			jQuery("#num").text( events.length + " / " + num );
		}
	});
	</script>
</head>
<body>
	<p>Move the mouse, please!</p>
	<p id="num"></p>
</body>
</html>