[{"UUID": "3fadb39c-e19b-44af-846e-29ef6766433d", "url": "Http://xx.com/detail/ajax.do", "Time": "1409", "UA": " mozilla/5.0 (Linux; U Android 4.4.2; ZH-CN; Coolpad 8297 build/kot49h) applewebkit/537.36 (khtml, like Gecko) version/4.0 opr/11.0.0.98241 Mobile safari/537.36 "},{" UUID ":" Undefined "," url ":" Http://xx.com/ad/ajax.do "," Time ":" 298 "," ua ":" mozilla/5.0 (Linux; Android 4.3; ZH-CN; Yusun L63 build/jls36c) applewebkit/534.30 (khtml, like Gecko) version/4.0 opr/11.0.0.98306 safari/534.30 "},{" uuid ":" 3fadb39c-e19b-44af-846e-29ef6766433d "," url ":" Http://xx.com/ad/ajax.do "," Time ":" 1008 "," UA ":" mozilla/5.0 (Linux; U Android 4.4.2; ZH-CN; Coolpad 8297 build/kot49h) applewebkit/537.36 (khtml, like Gecko) version/4.0 opr/11.0.0.98241 Mobile safari/537.36 "},{" UUID ":" 970119c8-3b2c-4217-a6c0-234500f3c050 "," url ":" List "," Time ":" 187139 "," UA ":" mozilla/5.0 (Linux; U Android 4.4.2; ZH-CN; La5-w build/yusunla5-w) applewebkit/537.36 (khtml, like Gecko) version/4.0 opr/11.0.0.98306 Mobile safari/537.36 "},{" Uuid: "864d4099-e698-47b8-832b-a753e9c61e94", "url": "List", "Time": "584", "UA": "mozilla/5.0 (Linux; U Android 4.4.4; ZH-CN; OKA1 build/kot49h) applewebkit/537.36 (khtml, like Gecko) version/4.0 opr/11.0.0.98306 Mobile safari/537.36 "},{" uuid ":" 970119c8-3b2c-4217-a6c0-234500f3c050 "," url ":" Http://xx.com/ad/ajax.do "," Time ":" 689 "," UA ":" mozilla/5.0 (Linux; U Android 4.4.2; ZH-CN; La5-w build/yusunla5-w) applewebkit/537.36 (khtml, like Gecko) version/4.0 opr/11.0.0.98306 Mobile safari/537.36 "},...]
There are a large number of log data formats as above, where URLs have HTTP link detail/ajax,list/ajax, string "list", "detail", "beauty" in five cases.
Now we're going to divide the five categories in this data, the usual notation:
for(; i < Len; i++) { if(data[i][' uuid '] = = = ' undefined ') {Undefcount++Continue; } if(data[i][' url ']=== ' list ') {List.push (data[i]); }Else if(data[i][' url ']=== ' detail ') {Detail.push (data[i]); }Else if(data[i][' url ']=== ' Beauty ') {Beauty.push (data[i]); }Else if(data[i][' url '].indexof (' list/ajax.do ') +1) {Listajax.push (data[i]); }Else if(data[i][' url '].indexof (' detail/ajax.do ') +1) {Detailajax.push (data[i]); } }
After writing it, it took 1000ms of time to find 11,000 data, and it felt a bit slow. Then think of the string indexof performance is very good, so change the loop:
varUrlstr = ' listdetailbeautyhttp://xx.com/list/ajax.dohttp://xx.com/detail/ajax.do '; for(; i < Len; i++) { if(data[i][' uuid '] = = = ' undefined ') {Undefcount++Continue; } Switch(Urlstr.indexof (data[i][' url ')])){ Case0: List.push (Data[i]); Break; Case4: Detail.push (Data[i]); Break; Case10: Beauty.push (Data[i]); Break; Case16: Listajax.push (Data[i]); Break; Case42: Detailajax.push (Data[i]); Break; default : Break; } }
Constructs a urlstr string, then classifies through the indexof, the same data volume operation actually only needs 3ms, greatly improves the efficiency.
JS Loop traversal Condition collation optimization