Search

6/26/2009

inarray performance comparsion

1.


revideo = /mp3|mp4|rm|asf|wma|avi|mpeg|wmv|mpg|3gp|flv|aac|wav|ram|gsm|divx|xvid|amr|rmvb|mov/;
function search_revideo = function (s) {
revideo.test(s);
}


2.

svideo = 'mp3|mp4|rm|asf|wma|avi|mpeg|wmv|mpg|3gp|flv|aac|wav|ram|gsm|divx|xvid|amr|rmvb|mov|';
function search_svideo = function(s) {
return svideo.indexOf(s + '|') === -1 ? false:true;
}


3.

avideo = ['mp3', 'mp4', 'rm', 'asf', 'wma', 'avi', 'mpeg', 'wmv', '3gp', 'flv', 'aac', 'wav', 'ram', 'gsm', 'divx', 'xvid', 'amr' ,'rmvb', 'mov' ];
function search_avideo = function(s) {
for (var i=0, len=avideo.length; i<len; i++) {
if (avideo[i] === t) {
return true;
}
}
return false;
}


4.

ovideo = { 'mp3' : null, 'mp4': null, 'rm': null, 'asf' : null, 'wma':null, 'avi' : null, 'mpeg': null, 'wmv' : null, '3gp':null, 'flv': null, 'aac' :
null, 'wav': null, 'ram':null, 'gsm':null, 'divx':null, 'xvid':null, 'amr':null, 'rmvb':null, 'mov':null }
function search_ovideo = function(s) {
return ovideo[s] === null;
}


跑十萬次
1. search_ovideo 41
2. search_avidoe 125
3. search_svideo 292
4. search_revideo 495

沒有留言: