Optimization of XMLHTTP return value re-encoding

Source: Internet
Author: User
Tags date chr recode return split
xml| Code | optimization

One of the top posts has a VBScript code that encodes the XMLHTTP return value, but is extremely inefficient ... I did a lot of hard work and finally made a very fast and satisfying code. However, the level limit or have to use the CHR function of VBScript to convert acsii to Unicode, do not know which eldest brother can think of ways?
PS: Algorithm optimization is really a brain work.

-x-x-x-x-x-x-x-x-Gorgeous update split line-x-x-x-x-x-x-x-x-

Every word I put down the test run time, finally shorten the running time of about 10 times times, now should be a practical algorithm.

I started with a regular replacement, each word replaced, the result found that 87020 bytes is actually about 40 seconds
Now this code on my computer only need about 3 seconds, haha, it feels so good

Note: This algorithm is not optimal for situations where you only need to decode it once, but it should be the best algorithm for multiple decoding.

<title>xml http</title>
<script language=javascript>
Web site for testing
Url= "http:\/\/www.blueidea.com\/";
Verify that the VBScript function you want exists, does not exist, write a
if (typeof (RSB) = = "undefined") {Initvbs ();};
}catch (e) {initvbs ();}
* * Global variable * *
Glbencode stores ASCII to Unicode characters, the advantage of which is that the decoding efficiency of repeated decoding can be improved
Glbencode=new Array ();
* * Initialization function * *
function Initvbs () {
Initialize two FUNTION:RSB and Vbchar in VBScript
strvbs= "<script language=vbscript>\r\n";
strvbs+= "Function RSB (vIn) \r\nrsb=midb (vin,1) \r\nend function\r\n";
strvbs+= "Function Vbchar (ss) \r\nvbchar = CHR (ss) \r\nend function\r\n";
strvbs+= "<\/script>";
document.write (Strvbs);
Get Web content in sync
function Loadurl (strURL) {
if (!strurl) {return (false);}
var xmlhttp=new activexobject ("MSXML2"). XMLHTTP ");
Xmlhttp.open ("Get", strurl,false);
Xmlhttp.send ("");
return XmlHTTP;
function Recode (b) {
var s=rsb (b);
S=escape (s). Replace (/%u/gi, ""). Replace (/(. { 2}) (. { 2})/g, "%$2%$1"). Replace (/% [A-z].)% (. {2}) /ig, "%@$1$2");
var unis=s.match (/\%@ (. { 4})/g);
S=s.replace (/@/g, "");
if (UNIS) {
var k;
for (Var i=0;i<unis.length;i++) {
K=unis[i].substring (2,6);
if (!glbencode[k]) {
Glbencode[k]=escape (Vbchar (eval ("0x" +k))). substring (1,6);
Tempa=s.split ("%");
for (Var i=0;i<tempa.length;i++) {
if (tempa[i].length!=2) {
S=tempa.join ("%");
return unescape (s);
function init () {
Sttime= (New Date ()). GetTime ();
Ree=loadurl (URL). responsebody;
Sttime2= (New Date ()). GetTime ();
S001=recode (REE);
sttime3= (New Date ()). GetTime ();
S001=recode (REE);
sttime4= (New Date ()). GetTime ();
S001=recode (REE);
sttime5= (New Date ()). GetTime ();
document.body.innertext= "Total Download" +s001.length+ "byte";
sttime6= (New Date ()). GetTime ();
strr= "Download" + (Sttime2-sttime) + "ms\r\n";
strr+= "Decoding" + (sttime3-sttime2) + "ms\r\n";
strr+= "Decoding Time" + (Sttime4-sttime3) + "ms\r\n";
strr+= "Again decoding Time" + (STTIME5-STTIME4) + "ms\r\n";
strr+= "Show when" + (STTIME6-STTIME5) + "ms\r\n";
<body >
In the download ...

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.