JavaScript で 空白 を トリム する 方法

0 件のコメント

JavaScript で 空白 を トリム(trim、削除) する方法は、何種類か考えられると思いますが… 結局、どの書き方が良いのかわかりませんでした。 そこで、この記事では、"処理速度" という観点で、その方法がよさそうか調査してみました。

まぁ、結論から言うと「ブラウザ毎に違った」という結果でした。。 メインとなるユーザー層が良く使うブラウザで最も速いコードを選ぶ必要があるかもしれません。

JavaScript で 空白 を トリム する コード (測定対象)

var trim1 = function (source) {
    return source.replace(/^\s+|\s+$/g, "");
};

var trim2 = function (source) {
    return source.replace(/(^\s+)|(\s+$)/g, "");
};

var trim3 = function (source) {
    return source.replace(/^[\s]+|[\s]+$/g, "");
};

var trim4 = function (source) {
    return source.replace(/^\s+/, '').replace/\s+$/, '');
};

処理速度 測定方法

テストデータは、アルファベットをランダムに並べ替え、0~26の文字数をランダムに先頭から選択し、前後に0~5文字の空白を付加して生成させる文字列を1000種類、準備、利用しました。 測定は、前述1000種類の文字列のトリム処理を、1000回実行する時間を測定しました。

測定環境は、手元にあったブラウザが Chrome と IE だけだったので、その2種類で計測しています。。

テストデータ
var testdata = ["pcwlqogmkyatbs ","  nkahkyifdsurcmweg    ","    ragkbtpjuqoimhysewfc   ","fkuiohblvrqmdtcpwzgnaksyj ","  qmpkgfcunevwlbtjkai    ","  gukcpsrtqhmf    ","   dneqylcfpzsr ","   lenktysc ","uwazqfokldhtkjpe   "," slmtecfdjkoazhpwvrnkgb ","  il","ikhofzluwnqaky  "," ajiweubkpk   "," z   ","   mcibrfogpklaezj    ","  nfmdhalbcjkuvzwoqespygt   ","wvqgylzjcmkrudnahtkosie ","    kzcjptu   ","  rdekzgbmohfajkycu ","  cfogymuvikhpbajzdknslqwte  ","    ktnjwmasqlkuhv   ","    gjqlrbhvdmfcapkuot","    bwomrqutdpglsvj  "," asiqwczyjtfogrpbnlhuekm  ","    djmopk    ","    hvcateslyjw   ","   sjkan   ","   ikwpfstubjraomdlg    "," i","   hqngdusbyltmfvziaeckk   ","gfisblywujrhkvqat   ","   qabwmekvcyfghp ","optsrnmgfhaykq  ","   olhvnifuywk  ","    nrtkbzywi   ","smqkdvi    ","   ulpbzjefdkyaqsgnc   ","  zsvwdlnkjuoc    ","   mesaginuhftkpcvjbdzo    ","   ","    urti  "," zhy ","    fyp ","    swdgnkzupjqerymt","    kdeq  ","rvnhimkedwlgzfskoatq   ","  zbwelvunriqjyhka  ","  ykhfersbctiwunmjqko ","dvpgwz","  wmilp  ","vaotehbzuqjikylmsprcn ","    hjqndgwlouzc  ","dkrkw    ","   jcpyrkihbdk    ","rvwzioacflmq","    bh    ","   vdnzac  "," ntewkzsqblpjyfiur ","   wqdbpna   ","   fzkmdtcnegobqhyas ","  gbdytjwpkq  ","  ejnhq  ","   ehkazigbtnsfmcvjylukop  "," khnvu    ","   kmiyd ","    bknwjahfgkirsey   ","   lrkyi ","    opjdkknfqzyiacstl","tgasyqwmufrcnebopjidlkkzv  ","  svwyuakomkfjdnhgli","   dngjpzyvkwqb    "," pfizomrwjsluknbevgt","vgjznodkcihesrwkmatu ","   wyteihupbjlrodsaz ","   gmfjnqacdlkhwpoitu","    sbwdpnlgqrao   ","    itrpw ","   fjz ","   lvrfiobhnpmgkzaktdeqwj "," plu    ","   lbiutqhm ","nsekhrvckjmabfiydqgzpt"," ojulgsiahmterqzvynbkkw"," dlrsitc ","   ke    "," cnjgkythiaw ","   iculvbnr  ","khpgckvlodwfnteabmrqji   ","   plcmjqwfdnztuibo    ","uh    ","azpty   ","  gsk"," qu   ","  gkkclepovrihqyfdnumzwsabj  ","  jpz   ","eqohipcurvzkyjsbwktga","   svdwjebycklpraqfgukoht   ","    wnbvkuico ","   msltpowki  ","    lqyjkasktrezf   ","  fclauhogeikynd","   b   ","fzstyaqhwulemid  ","zjsdbmftkwlk","    galvtpwezkmhsucdnrofki   ","  nphecawkkvzfl","  ywhzvfjuplcrdgonqmkbtask    ","    kobhdterkvacnsijuyglq   ","  ","    ","  bavfewgmjqhcknkopisyd","    jmurofwpasktvlzcnbehg   "," ehqjndtzvmpg    ","    wqcg ","   qkgzsurhjktencvd","    iewhg  ","  bmyijkcslgnphrq","    tfksnympchkuldzwar "," rykhvkdmbtoeszufiqa ","    woncjdkfamhkrusvpi   ","  ejbuzmnoyckftpagdwr   "," mlipvcjwhatgrdb ","  tnewvgfkauojclsiyzrm   "," aiohnscwkqprzj    ","    wmva ","    v","   emvzhrulkjdfkgsobwtaqi  ","l  ","  ajhitfm  ","   ilrf "," jpmshkkevfq ","  ih   ","   mwrlisnchapeg  ","  qkobzkangcmiwpetjdhvly   "," vedcngkskhyqrjazwm  ","  bgevloipj    ","  zwhd    ","   yawkpzcvfudklb   ","    hekmfjuqskvnwi"," fionhywukpdjqkczgaeltvrm "," uescfbawgrkvnidytmpho    ","  uelhqstvojpgdmk    ","    obkufvymwgiensjlzaprh ","   jkbtpqvzflwredsokghn   ","fpydneil","  gofycmrw "," netacsfqlubovkr    ","    kzavm ","grbejhuq ","   uiveyjnt    ","  cozwnekv    ","  cmspoklkuahqbgzwjfn   ","    seikczthvnamfdwlgboq   ","   rpvmiqugdlzyakbosnj  ","      "," zkvsaplfdmounrwycgjq ","   da    ","  eqav ","   lfnp   "," jktnge","    i ","jqyukvinblhwfdzoepgakcts   ","    skleydavpfonbquzktrgw    "," qsktlonvk","  ikuhdvkq  ","   hrmkl   ","  juh   ","  rlhjobkq","   mbkihotnseqcwlrupaz  ","  qwabngkpsvjlcftemhzkoy  ","   ojnq    ","kkj "," qaofdelryhckztmbjkugs   ","  wckualfspoqytbjigh ","pwljkvebdagrqzmfytcs ","   dvityakfkbslprcgmwjquhz","  zhwgkv   ","avtqugoydirclnbjspk   ","ihkpbqlnzwmkadfycvoestujr","    ksahfdlyutcqjzowgpiebmnv","  panzoigjhsvwdefmuyklt  ","hkvpjbsyudifl ","  y   ","   yvpuqdekzcnkjogmahisltrwf  "," ybkjirkhodguqsvep  ","avidkfbugnw ","  johgmkbtdina ","    l  ","   cvswkop","   ajchfyzoiknsptvk ","kfdheqgluvsbyzmtjapcwkr  "," fjgpquctzkhbnmorsa    ","    ypgekzvahfmocj    ","wkacikpgemlyvoqfbhzjr","gwtbi    ","obspdti  ","  fywzkkjusnbmridvtploqcg   ","   qakj   ","  pkhokjsbmrdyaitflu","    vomlafeujqsdpcibkyg ","    fjpql   ","    yvfwargceukntjlomksdbhp    ","zadrmvkchtwlspekbyj    "," qbyersdnia   ","  umenzjlcgbtvkrisaqydwfho    ","      ","   riboykplfqhuvdkwjnezcgas","   koblgfusyczhdnkqejtpvmriw","  iscgdvuqrjkat    ","   a ","    puwcrslmkafdhqzkoe   ","  srz    ","lthzfgvi  ","    ihndrvufbajz   ","  vgkfhurqjk","btwclfkqogui  ","   hmnitqzcdjylwpkrgobveska "," zvlgyufsknwjh ","    dgmc   ","ikvn "," ktyihcejalnwdpvkm   ","stlcbwjpmdv  ","  gwilteafbnmkhsropkqyjuzvd    "," efcrwlasdomkvgtkh","  kmlueiyr    ","  eq  ","   wnkvlrteybmjgfhkapiuzoc   "," zikhujwvkrqtsaopdfbyl    ","    nwkiglbzacfhome    "," snktdapyr","zlgjksaowyftdukncmbep ","   vrhjcfwnlzyqdbka    ","  ikwqhmplfotcnbygadzrv  ","    ph  "," uiakczvty    ","    soqhptvujibamcfkkynwrzel","mpqcdwz","zlhvitrkaokcbjeyf  ","    ou","    trqzfbcsgvopludwmkiekj ","  lncibmrozdgpuwtfykqj   ","ghzblojwvdrqemckayts   ","    ri    ","   hfqjaknury   ","      "," rtpqcheofk  ","    byzjpitohlmrkn    ","    ","    gkshwtvckomnpiujeqrd    ","   oakjwilehdk    ","eumljriv ","   bruahngzweoykjsfcm","   jpewqthrsglfuvkozdkm ","yimnpogvjwhqztkrfebcldu   ","    kzeoqudarbpmj","   ufbpaviqkkswljey   ","    kwarlpobchnedzfqjum   ","qszlhekywnajcifdvtk  "," rfejdzuqwhlpoi   ","gmdpozukvafetbchlwsqyrjni   ","   pydgbtkoclnsqjzamer  ","tvugnwzb "," dlfreqpiwkz ","  knsclvzeuyw","  flediabk   ","   cwnsliyjqkurtzgodv  ","    kmnafdoyzlqpbhk  ","  tjkosd  ","    sylqebunkrgw","mwczhjfqot","vpbescomkdtrhakynjgfiqz","    rokihn   ","   arysklhc ","klunjmqovfwgr    ","ruokiknjhapdszybwvmlfce   ","  qvkaenlo ","f ","   o   ","    sj    ","   leavibfqwymsn","jbiazlvmnchtfkeko   ","  f  ","     ","  mefk","qvleifhcymkagopkjnwubs    ","rbmqkondltsvgjhczuwi","  v  ","ifqb","    qnjkbpgehzo   ","    gzwfdcpmt  ","   icz","   rlckobyu    ","    gezlrtwfqyabksjdhonckpui   ","  ymujckpafbrstdlhievgk   ","  ydfbvcshqnrgakm  "," bsfzvhgckdjruitlqo   ","    maqrjzkgpcoftuvlhdsekwi  ","uygizdpovtj","  mfsvjryboiahckzqdunk    ","  damnzgck","    ghv ","kuitqbcgkweylfardom   ","ruzqgfsvilyc    ","   duqajwolkckyesvfm ","vghr  ","  vtughojpecnm   ","uvtojmnire","    hainy   "," matkusjlowczkdphrifnq    ","    pfqlkakuyswcmvi"," lnducvsygoprhk","uytakvjnroz ","uaijeyqt    ","gitw   ","  kqhrvmefijnladkcbwsgotzu ","    ifaz","ncyqfrkuvlmpjwaozikdtebs    ","blwamokrcqtziednvfjpkhug   ","erwkbdik  ","  mhgpbslfjdrkn","tepjsrmkcayzfnwogkv    ","  oaekwmisjrkbhfvc","   rjlcmbnqyksgwpvdoahfzet  ","     ","kvsmbzfenoigwlru    "," bglvfy   ","   yn "," tfjildzspecukmobvwnqgyakh  ","vkbcazpsfginho  ","rhuq    ","  kea   ","mtgyaoewhfdkjrnq   ","ukn    "," k    ","   kyhicudqlbjanpkgsotrzmwfv","   klfwmghojuci "," ftelpjrok  ","  rkawnpuj"," kgetkfjb   ","    myljcagozsdtnfuh    ","    a   ","    faletcnvmr","    emjqpuwvngatfdyblsh ","  ulofrykhikgc  ","  zmngwhpkcitladfeqysrb "," yqbucisozathgvpdekrk   ","  yeodwztfqk ","   huoigqjsmfrvbkpk    ","btkshwyfpjvulqnodzmgiea  "," enqylbokjikzsrtgucdvh","","   nebqawikouftmvgjzypldks ","   hatfozjrvspiuqkm"," hcgayotplwdrjfzvebkumkins   "," aplqkwmoucsfke  "," dhimla    ","  hamfnkpozleivuysk","  jkptmqokzbesucwfvdirnyha ","  kzqrj ","    zg  ","  alvputrqkmwbgfdcnkeyhjzs  ","   gjwuzvahqldepmsrkbnfokyc","  emqdknygfwr    ","    ehf","   bkuzfktiwvc    "," w  ","   eucjsqgfpywtzonkvmklaid  ","  niohsdzeujkalqkympt  ","knikzd ","  ms"," vhsrtqkpk    ","  zbsedoktilyngjura","    bfowzkchdrqveulgamiyjsptk ","    oepjnywbmqckg","  akeqhoulv   ","tjkqlcevhokfprgymudwzbian"," zltdswpmega"," uirdpgcqhnm ","  akrh   ","  ichsbnrmyzavwt   ","    talbndphcrkveq   ","   kjfoyilpdmrhb ","   jtezwpkybvdmgursql   "," vqukpytz  ","  ayrkegljwfhoknvpqdibtzcsm "," hkditbcukgnewqlazr    ","okduhakcgyrnpizjeblqt ","  mvjpfko ","  zpsfrjmakngohyw    ","   rbwkhzviecgqkjmoyflus    "," dwjfmrnezyhocvuslbka"," ogk    ","  sfegd   ","   bcntlydwkqefkvupjgoia ","  unjzwcdklkrahsqigepyobt   ","   hlacripbokfnyjevqkszwug    ","   kyqczmrslikvgjntpfwba  ","   faktrgmdqocwesvnpjiu "," tvyqcalfnib  ","engohzsiacflq ","   kmeqrbifjcuotld    ","  krtybmcpalfeokuvwnzhiq  "," lcyzrkkejmb    ","mlabgtrhko    "," "," kolyqkhrte   ","   fatosczermk  ","   tanfie    ","cmisp   ","   kiydsewqzjh    ","  ndzmvfrg    ","   jfrug   ","    hltozimuk ","    tfyakzsgou  ","  qnpr ","  kvlduhqey ","lcsjpknekyfiohvrgb ","kkaqdlmwynzfocrpiebstujh    ","  gkodfyiuzr   ","    khogklirv","    uojw   "," mqkndizrcphgyveuakl","    eorkpiydzqa"," vbpmwjknkoaglyisuecrtf ","lwkipfthvmnadr   "," nogaklvkrqwyiuztf    "," gqjdrwhzkblopnc","  tpnczskragbewmvf  ","    mrgqyjfzsuhic    ","  kktsicqgelnrdozmbwpyfhuaj  ","   yobpev  "," edkymcgspzfkwqajhuon  ","  lbgnwckathrqmfyzekuospi ","   hcu    ","       ","   hujcgimysaflkzrqtbdvwk ","kuf","    jvoyw "," grkavonlybmctze    ","    gczwnbvpfmeqkdrhjskail   ","   cphmtnyfkbqkjervla    "," yjelhkvtbqkzcnismfawpgrod  ","mfd ","  stcfd    ","   ey   "," nbjrksdhzqpmwctlkovgyefia    "," os   ","   wosctaebfqmuilyjv   ","    fgkhtbinywokc    ","    ekihmdua ","  bkpw ","lvse ","    dfe "," zcof    ","  rtdlkikswgonqevh ","   hjopunwsiftzyk","   tg    ","jfakmqlbvurzntswhygcpkiod ","  bvrhqgaeocwjzsfkdynikltu  ","  rj ","    epvmtjfcuhl   ","jbdqhefzlturkcgpyvsiakon ","    wmskgpftbvylzeiaoqjdnkcur","  liwtrea   "," zsvknqpghalwky    ","  zfequymdawibjcgnotvlkrshk","   vkyqrwuopkaiegbmt ","  ehzws  ","   ep    "," zvbfkqtgcj  ","  yjigmokbwtzcfsr ","bjuasltvdkkqwonef    ","  smuchyqdwnvi   ","  syikmjolvfhcenqbwgdra  ","  zmtusknqjayd   ","   jnvotqluwk"," iodqhfgnytkbvwzpculek   ","      "," pjwcl    ","  qolnmjkwuhfpvte ","jhtfbezsqdwaupgvkly  "," fspzdoqrye ","ruvhzdlgq","   bokmlvqkndsyihfzrtapge    ","zvmek ","dtc    ","hjvisyd    "," ","        ","zihyjbemkdpvufo"," ","     ","    ehltnikfboad  "," drgalmicjynzesvwoptquhfbk    ","  kfvetdniqcojlbusmparh  ","vmfqizjdo  ","   brqupvdekkfacwj ","    quwy  "," kpvakbimuyqwjtf   ","   svrjgtobzymqnf   ","   vetcjgkaydzlhk","ubphaqwi","  wodbygtvklnmfchsipa    ","   db   ","  qfjkkacnuriyetbldz   ","   nzueairpvdhbclmtkqfgkos","  kqocjinkrdpv  ","    o","   jswzkptncaqomy","  jhtdsizegpvlnmufkycqor    ","    kufbrzosdj ","kzhqevnt","   lrdfukjhegmvznyw "," okjrswf  ","    imltvqyoa","nezdmcvf   ","whtgcpznflsuoibmkyejd ","   ","vkicgruedmqs  "," ehldpwtvizjkmoauqbkfn"," av    ","   wvl   ","  pfrucemk   ","   umyjbzrkatlogcnwidkvq "," cmrybujlkkapz","  jpswl ","    bwpv  "," eqkhzprub   ","    hsekdpcazrboyimjnlgw","   tduynklhepcisfo","zukbkie","esynotkdbjvwfrg","  uclz","lam   ","  ewoqzlmkgjnp    ","   raqhpkvmtusnicegwzfy   ","dfgqkpzwrebcvy    ","  ","gdfmlibntjzopqaery   ","    huonm    ","    iagolqtwp  ","  jhlqktdzrpw","    izmkjbwhlykcr    ","    ckzmbtuhyvlrpiaoj","tmkcakpjv"," fdcqnwibprljzgykvakuhso   ","  fvoytupdrsknmilwza    ","   ikevtonrfaucmkdsqwyj","    "," iurcjkklvzmywdpoabnfetqgs","btywsrkdpfqhcemnkv ","   zlobjrshmnugwfyviptcqd    ","ptbzrdnofawjgeskkcyh  ","    ltgrikwnfyaupvjqcdsh","   wey  ","   cnjbzokqegmyvklsd ","  ","rlgvuiaeb","    yezibuqfo   ","     ","    rdhzglbnwuoksetqiyfajcpvm    ","    frc   ","   oziefcgwaybjdku  ","   gyocrbqshil   ","    pqytr   ","   mpwisveafnkyuoqclb  ","   qczmfdkiyneavtglwbhkjsour  ","   svmkjuribctypazqkdeoglnhf","   tezhskrcdiavfmkwyonbug  "," nudkwymolazpgikecbvqt","  hrknmwdezk  ","  svtkemgjhfdr"," lfpar  ","  toywakdsu    ","topbhnvfesrijym    ","  pdweqmkubilvjk","    kpncwgsuktoijbhdfy  ","  wqhjoailpvtebfrmznkygdcku"," dojlkmiczhr ","  eaiuf ","    ","zuwkmpvaegqhdynrbktji    ","  tkfwljardshuimgcqzp  ","   hgwbmidautljfn"," cstihdarbeyz "," cegbpwyrkokusmqlndiztv","    ejiwvhgn","   uvqieptlcbhjagkyfmdw    ","   oh   "," jgcoiqzbavfkuslknprwdty   ","  gekdwhoirv"," keunpqmbivsoyjzk","    rcqjtzfd    ","  okurkmdjlihbwz ","vjkcsktwgar ","  jhtrik    ","csafrkomlpdtuhveqynbg ","  hydqjzkbucntfargksvipel  "," bcmpowndiavrkfylqeusjh"," abmz    ","   pyzkeodcfbrutvn","   jgvolkpnzhekyqarbmuidsfw  ","cblpazyqkfgkrnmuwesthvoij    ","kdatgzoemuilnsqyv  ","   ouwtimclp "," qgvs","    piqeaof "," wqsmikflaovzepbkhunygdt   ","    ","hlkdkwremszayitvqf ","    dqstbrnygm    ","   dunwkjymtkq","    kjuyhisdtk  ","  b    ","  pisndocaqmz    ","    lfrgyaeoknpdbu"," nwgblmhyfuscievzkoqrkjpta","  plhmgozajc"," suirwegtjkhyoknl ","omftjqhrylps   ","   hzvbiefqatgku  ","   sjivrkadutpmewcnbfzkgl    ","  ypz ","    ","  gfudnkijkcp  ","    jnyzwstmhiqackr    ","       ","wvusqmyrbnfdaclzpgjhkkit    ","etibdfackujglqk   ","    bkwutkelmfiapyvzjsq  ","  kiahwcndqorbu","niqzcjtlgrwep    ","  feoutzsdbgjarkcyhi  ","ysozcltgvmihfukrpqenj    ","  swehzymparuin   ","  "," iankuesvpqlhtdzmbkwgroc","   gudqky   ","  nfwviyezctoglmusq","    kslfprtivhjumwnzeqbcdao ","    qzov ","    ktzkebhnglijcpqwyvf   ","    erkbshgtl   ","  ybtoajfw    ","  r    ","  ioygmtv","   pcwrtlvodezqfjnksakigy   "," huzrk  ","    ajzkgybidulf    ","  nkjqolgskebcfpyrai  ","  tiacml ","  qkoywclfnre","    whiaysg   ","  svpz   ","   jvrhwgycklzmtdoibps","  livoswjcndgekhzrtkb","   jtzapgsdwkcmkqre   ","   kugojtlhryqbiazn","  cilpamndrkqz  ","    brdfsymuwip   ","    afkbcjqmluv","    ","   prjofwsazbktgiykvhle    ","    yohzrgvdimjkflecstk  ","  fkigwolkqhjv "," cpgbvlyikesw  "," hkuk    ","kmcdkusthzgjly "," uezlkyhpo ","  aqbzumfygljdtpwsrnkhkev ","    emaj    ","    kiudayfvhecplbnw ","  zaegdcyvtpjhkmqnulfo ","    hrwimdpgv","   crhgaeilsypnfqtwdjbvozk ","   "," fkhtom "," eitokmfwpdkugnr","   uvicewrnhbagz   ","   palt "," dkkmlochtaiebgvjqnwsyzu  ","   jcyatswnudlhekgz ","  dinkzmcgkqvpwb   "," qlyimeowbjvshngkfzrct ","dyuzewntlifsrqkvkmb","      ","  s","jhtakdwlqfcnigvsmrzyebpu   ","mus  ","wdsiekrv  ","   dvkywbhiftnrm   ","  ypiet    "," m    "," shtdkivzanq  ","    qywgpbovjkt  "," kbcdalkotfyuh   ","kfewktjguazyqlrmoh ","    onyiecprzqgaft","   hieqscdbt","    gkvctiwezfnjklar   ","   ozlrdbcfgyhtna ","   arfcgmjytioekbzwlspkdqvhu    "," yofmptjwrevlgsakcbkziuqh ","   bdqmoeklahjfctwnpuvr  ","vsypknfcmuwjehgtbqkrilaoz  ","  mhurzywtnv ","    gkjfmatnbcl  ","   hizgbqkkyrlmenucdv  ","    gvstulpwijbr ","   "," famkgrcineolbdwpjqvu    ","   tkuiyzqrbnspfawvkmjgceoh  ","   cvnrqjyazwbiftukgklmhped   ","  ebfw ","    grokevtjbasclhwnfpkzymi    ","    kmnlvodftapbz    ","  aqnhzvwjyortgslbkfipmde    ","    lkbkdfzwcjiayhqvstoner    ","   nt","   idg   ","   pojqcwetaizyn ","  nvslfe  ","    mzkrehlfnd "," gvotecahuirqzmpkbnydks   ","  tdmlnigehs    "," pkjiswnomgfyvbak","    vgnrsoupajmdy   ","   oyeilapnkvwjcgqdhr    ","  hirckjylg    ","tvczkiredakwg","        ","  ephzrnbyitkdm "," vctknokbjp   "," zd ","    nksytgdpuowcqmrble "," hfugveajidlynts"," vkzlkjsumdeg    ","    nkzpmfjyiqecabdgwtlhvr","   wybgukqmnozlpt","    ujstkvzrihygwn    ","  ugknmpe ","   umzjrowldpcktbfg   "," zfkcpsbjyokq   ","   qakyrhptbvw  ","  wurcgjnkloemvdkzfhyqp    ","    gfaishyzewlnc  "," tnsklirz    ","   qawpmkfdgsilzecnbrotkuv  ","   hcbnepdkuvokmaqryfji   ","  hqtejfobapnvdkl   ","  gutslncjpzwor ","    cahtvkrbkfjlsyzmiwupg  "," piuhkzjgfcsmkeqtawvl    ","    tdfuwn   ","gzkfivjeulpqa","   yajhlqpwcn  ","    lmqbgwcdekpvas","  mqibksvapklfod    "," kqzjvafcodlpsmnihrut    ","    lkzemhrwsdfopcjyq    ","  jczyvnkthospad   ","ekhoiksu  ","   metsdof    ","    r ","  nsokudiyfmpeha  ","    kdyehza  "," wifk ","   qzgclbvykepdrkwojitufh   ","   fomsrkpagzitlujnyvchbkw","nwurpgtzsymlaedf"," tezipufqrohwgmadsjlcb    "," ejivfgpmsulrych  ","    qajpzgonuckesvtlybhi","    bhitnsuqmelgvjafyp   ","    n   ","      ","    vukkiwfobdjgnyq ","    jvkbzlsir"," kun ","  brmasdqykjifeukohvz    ","  wgrvpoulbmdetfqycank  ","  ilhjgntyawecr    ","   juqzm    ","   arcisy    ","   bhtdqrsifpouleyknc ","rhikcbygsw    ","    dpcntseiq  ","  oynltfkecphbugiqjwksrzad"," iszwnkmgopkatqur ","   tnkvwzjodasbei","   hja   ","    lmvtdcbpsh   ","  anbw  ","    geqobrickztjwdpvlfsam    ","   upwto   "," sqodrvb  ","  rimvbdpukkjeqfazo   ","      "," sbaglwfthezkqpuckynirojvm    ","    gpkutejzfbiyrkhwvsola "," bkfzdaktml   ","    jpqedguzvofmastkwkcnibylh   ","  kyunzdwirhojmpgstabevl  ","  wikljuzvtograkc   ","  sqkpuoldjitbnrkhvmwgzaye    ","   yrqzbgpuiaf "," epchazrqnswfimk  ","   ntkrzlpog  ","ehlytawqpvcdjigk  ","       ","    odi","doakvghpljwifrnstmeqbukc "," gfremhnvywdsqokbc  ","  bnzkrmcfqkuhj ","   lhms  ","a","  arzem   "," cohakmfrjszpyqln ","   qznwpurjskky  ","  kohjungq  "," reliskg"," fwlgsyomkqebzuchdvn"," ztnqcuekwyfmapgkhij ","dyuhkip","ocf ","      ","rjcbkm   ","  vmtgdpharow"," pngybkr    "," iordwez   ","glmnweyzptakcidhsobkvqjrf   "," lzcehp    ","   lkadnzocvumt "," nwgylpdiorhekqbuk","   bwqadokchunfl ","tgkrqzhjbs    ","oifwbhmtkrsgc","    mnewckkhaz","  cjphqsdwanoe ","waldjifusy  ","tmqukyokrvdwljah ","    asdvrtkulcm  ","noafyvkqwushtgzemk    ","sakredvlbfmtgk ","ilywkmnogtpjvuhzrdke   "," pnlaz  ","japftbhyivcwrdnzskmoqgul  ","  apckdyufbqtim ","   crwykpdzqineahb","bmjtgqficvul   ","    dcsqzrnhvalgbokftyjwiukep    ","   otikpd  ","      ","  dsbzthfrlingakveqcmwoup    "," kiljbzhfomskwprcd    ","eywrhojlacvskqm   ","ilfqvztjokhrbucnmskew    ","  grectzsmvnkludqbfyj   ","aputzrvidmwfkqybeckh","   s   ","   rwjdkokhf  ","   jbdaqskozkpecw   ","  metwkycgvoujrlhkbqa","    tywfn  ","   kakt    ","  kbhj    ","jmywohfpdtbecngks","lqn  ","sqjlhgzvcd","dyvhgunzoeq   ","  pcsijeguhortazyn ","gufqwhe    ","  avft  ","  kknj","    stpqmwykcofguvjzdkbn   ","   uwnvskmpqhz  "," mahirkyde   ","rfkuht    ","   dypgwlmrvtkisuczfb  ","    vetohmwfj  ","tozyqagrhdkmknwp    "," gtykqpmjknrlwbvzfehsuadc","   tnqzuye "," lqfv  ","    ysek   "," emdfp    ","  rhpkiuj   ","daocbevlguynfqtipjhkmzsk  ","    aiodmspjtcqgvrhulkkez ","    iuzklfrokesdw","   jwnlyvrtcqigmkzufbapkdesh  ","  pj    "," kqfmaveucrh "," uvt  ","    mqhp    ","  omtdpkejiyvhasfcnqk    ","     ","    zwbnldrkyip","ukkdnbhro   ","m  ","    evsidqakpmgyozkr ","   fuovrlkwqshpdcbjmeyatki    ","   hflwemagoyku","inlkrqmouhfdcyvejkgzbtp    "," s  ","   hmdfsjarvnc ","  sqczorakmlidygkevfuw","    okhzrngsfdvepkuqc   ","c   "," klyesrpakjnhqgdimuztwvof  "," jfngidlqsktovc    ","  zbtjenkl","mstzbejokkfrpailunwghqyv    ","   sarwknzdj","    ypwboj","   hovkd   "," ekutrplnzswamdbho","  lwajro","  gzu  ","    o    ","zqksevdn    ","   ocmrkfjezapsythl  ","   urmk"," dgk ","  ktqwfkjobzchepdsna","  caqrwdbsjguoknfpkm   ","    iug    "," cka","  igynouzwlet   ","  ewz   ","    vjwst   "," ie   ","dtnfevzwkumj ","    jaeokzlwtbvqrngmfk","   pardtsoeq","  pl ","    opmngdtulqcjvibfykh    ","   nkqd"," rafkiplmhyjd","  gcl","  r ","    t  ","    tbldqysjrcefhzouwgmk ","omcz ","   ezfhrkbtnpjucmvdi    ","   uejpmilbqgksnzdchwtfakv    ","  krzocpdfiqsevjybuag   ","    zovgejkknqfrimyd   ","   jpzodqewmlfkk","rnvlzcfmkueitahpgk "," zgfkihrdkbtwem  ","  kewzcp"," kkidltqcp  "," kmjewtiuqdor","   wcayskivfopzjr   "," kjo  ","sdtm    ","  buognvzpyiweqltjac    ","   tpoakufyqkimvsedgwhj   ","    besunhgotrzmpfilcyd   ","   hmgikzqypflbnwdva    ","rtqlchvbzdy  ","   bjwmosfvet   "," fmhvdjzytqipsrnok   ","   rzicpdkyqskbw","    iyskmnbegpjcwfukdr    ","    z "," jezbqnlpr    ","hesovcfrukwbjniaqtdlykg   ","nkg    "," gjtpekmovu    ","ilwafngvbuy    ","    rckkopuqnfheimjvlt ","z ","  ytovk    ","   sdclrfkzhtjbnipvwemqygkua ","    lfdarhostwvupikjcnbzmyeq","    rqygutkpaioekblmwvfzs  ","   qknoiryztbfguvpldjkwesahm  ","yrloabumncdskwgi"," cia   ","  n   ","    ug    ","zd","bketajpmodcvyhsrigzuflnq   ","   lmistbwfypnkvrazkcoqjghu   ","   csgbdtnzhuwyelrkqpivjafm  ","jnhkrleboavgwyqimfstp","  rkjfsg  ","ilvkmbesqapdt   "," akgpb  "," bvwslujfzncrtahkyqdeigkmo   "," rqdokpfvealbtkguyjsc    "," gaen ","  gdmlikfykuzcbqhtej  ","    sgbekzrqtouwvmpyidkjh  ","cwehbmpjvfrk  ","   jqm   ","    retukmlkqdyancgfh "," gavylzbwnkdsqmko"];

処理速度 測定結果

Chrome 40.0.2214.111 m 単位:[msec]
  平均 1 2 3 4 5
trim1 982.8 529 334 1338 1337 1376
trim2 1181.2 429 1326 1401 1370 1380
trim3 1068.0 420 1378 1064 1194 1284
trim4 484.4 335 1118 305 318 346

 

Internet Explorer 11 単位:[msec]
  平均 1 2 3 4 5
trim1 1633.0 1578 1333 1961 2223 1070
trim2 1112.4 1080 1040 1091 1291 1060
trim3 755.4 585 560 612 1415 605
trim4 917.4 453 446 450 1658 1580

まとめ と 考察

冒頭にも書きましたが、結局、ブラウザによって結果は異なりました。 ただ…使うなら trim3trim4 が良さそうな気がします。 本当は Firefox、Safari あたりも調査したいところですが… また、時間ができたらということにしておきます ( ^ ^ ;

参考記事