OLD | NEW |
---|---|
(Empty) | |
1 | |
DaleCurtis
2012/04/10 23:00:06
Header w/ details on where this is from?
Will thi
| |
2 // The purpose of generateSrc() is to return a URL that is not cached. | |
3 function generateSrc(src) { | |
4 return src; | |
DaleCurtis
2012/04/10 23:00:06
Dead code?
| |
5 var ch = src.indexOf('?') >= 0 ? '&' : '?'; | |
6 return src + ch + 't=' + (new Date()).getTime(); | |
7 } | |
8 | |
9 function Timer() { | |
10 this.start_ = 0; | |
11 this.times_ = []; | |
12 new Date().getTime(); | |
DaleCurtis
2012/04/10 23:00:06
Why?
| |
13 } | |
14 | |
15 Timer.prototype = { | |
16 start: function() { | |
17 this.start_ = new Date().getTime(); | |
18 }, | |
19 | |
20 stop: function() { | |
21 this.times_.push((new Date().getTime()) - this.start_); | |
DaleCurtis
2012/04/10 23:00:06
Extra parens seem unnecessary?
| |
22 // console.log(this.times_[this.times_.length - 1]); | |
DaleCurtis
2012/04/10 23:00:06
Comment?
| |
23 }, | |
24 | |
25 average: function() { | |
26 var sum = 0; | |
27 for (var i in this.times_) { | |
DaleCurtis
2012/04/10 23:00:06
In w/ arrays can get messy.
http://stackoverflow.
| |
28 sum += this.times_[i]; | |
29 } | |
30 return sum / this.times_.length; | |
31 }, | |
32 | |
33 reset: function() { | |
34 this.start_ = 0; | |
35 this.times_ = []; | |
36 } | |
37 } | |
38 | |
39 function Benchmark(video, src) { | |
40 this.video_ = video; | |
41 this.src_ = src; | |
42 this.cached_src_ = generateSrc(src); | |
43 this.timer_ = new Timer; | |
DaleCurtis
2012/04/10 23:00:06
Timer() ?
| |
44 | |
45 var me = this; | |
46 this.video_.addEventListener('playing', function() { me.playing(); }); | |
47 this.video_.addEventListener('seeked', function() { me.seeked(); }); | |
48 this.video_.addEventListener('suspend', function() { me.suspend(); }); | |
49 this.video_.addEventListener('error', function() { me.error(); }); | |
50 }; | |
51 | |
52 Benchmark.prototype = { | |
53 reset: function() { | |
54 this.playing = function() {}; | |
55 this.seeked = function() {}; | |
56 this.suspend = function() {}; | |
57 this.error = function() {}; | |
58 | |
59 this.video_.src = ''; | |
60 this.video_.load(); | |
61 }, | |
62 | |
63 testShortSeek: function(iterations, done_cb) { | |
64 console.log('Starting short seek tests...'); | |
65 this.reset(); | |
66 this.error = function() { done_cb(false, "Error loading media"); } | |
DaleCurtis
2012/04/10 23:00:06
s/"/'/
| |
67 | |
68 var times = 0; | |
69 var timer = new Timer; | |
70 var firstPlaying = function() { | |
71 this.playing = function() {} | |
72 | |
73 timer.start(); | |
74 this.video_.currentTime = 1; | |
75 }; | |
76 | |
77 this.seeked = function() { | |
78 timer.stop(); | |
79 times++; | |
80 | |
81 if (times == iterations) { | |
82 this.reset(); | |
83 done_cb(true, timer.times_); | |
84 return; | |
85 } | |
86 | |
87 this.playing = firstPlaying; | |
88 this.video_.src = generateSrc(this.src_); | |
89 this.video_.load(); | |
90 }; | |
91 | |
92 this.playing = firstPlaying; | |
93 this.video_.src = generateSrc(this.src_); | |
94 this.video_.load(); | |
95 }, | |
96 | |
97 testLongSeek: function(iterations, done_cb) { | |
DaleCurtis
2012/04/10 23:00:06
Both these functions seem do exactly the same thin
| |
98 console.log('Starting long seek tests...'); | |
99 this.reset(); | |
100 this.error = function() { done_cb(false, "Error loading media"); } | |
101 var times = 0; | |
102 var timer = new Timer; | |
103 | |
104 var firstPlaying = function() { | |
105 this.playing = function() {} | |
106 | |
107 timer.start(); | |
108 this.video_.currentTime = this.video_.duration - 1; | |
109 }; | |
110 | |
111 this.seeked = function() { | |
112 timer.stop(); | |
113 times++; | |
114 | |
115 if (times == iterations) { | |
116 this.reset(); | |
117 done_cb(true, timer.times_); | |
118 return; | |
119 } | |
120 | |
121 this.playing = firstPlaying; | |
122 this.video_.src = generateSrc(this.src_); | |
123 this.video_.load(); | |
124 }; | |
125 | |
126 this.playing = firstPlaying; | |
127 this.video_.src = generateSrc(this.src_); | |
128 this.video_.load(); | |
129 } | |
130 }; | |
OLD | NEW |