Js|jscript|vbscript Guide
Which language is better for VBScript and JScript in an ASP environment? This article tests the time required by both scripting languages to complete common operations, analyzes their strengths and weaknesses, and draws some noteworthy conclusions based on the test results.
Author: Cactus Studio 2000-12-19
Original source: http://www.asptoday.com/articles/20000920.htm
Choosing a scheme system involves many factors, often related to cost advantage analysis based on performance, capacity, maintainability, employee experience, existing foundation, and personal preference. In a typical MICROSOFT/IIS implementation, this consideration continues to expand into the role of ASP in collaborating with a large number of different COM + components: At an extreme, performance is far more convenient than programming and maintenance, and ASPs are only "binders" for integrating business logic and user interface At the other extreme, the ease with which programming and maintenance can be achieved exceeds performance, and the ASP itself is used to implement many business logic.
This consideration can even go a step further by analyzing the relative strengths and weaknesses of the ASP's two main scripting languages (VBScript and JScript). Functionally, people who are in favor of JScript can say that JScript offers advantages such as better error control, inheritance, bit manipulation, and a client-side, server-wide scripting language, and conversely, those in favor of VBScript can say that VBScript has its own characteristics, such as the extremely rich localization ability, the case independent code, the more simple intuitive syntax (certainly, C programmer to this point will have the objection). In extreme words, we can not only achieve such a different ASP page on the same site to analyze the strengths of the two languages, but also within a single ASP page!
Although it is sometimes possible to simplify programming with multiple scripting languages within the same ASP page, it is bad for performance. With a cursory consideration of this issue, we know that running this ASP page requires a two script engine to be started and cached, greatly increasing overhead. (And even if we can ignore performance issues, mixing the two scripting languages is inherently unsafe because the engine buffering affects the order of execution.) In short, ASP pages that use two or more scripting engines may not execute sequentially if the developer is not careful. )
This article is going to delve into the performance problems of VBScript on this Windows 2000/asp3.0 platform compared to JScript (and VBScript plus JScript). Specifically, this article will answer the following questions:
is one of the scripting languages faster than the other?
If so, under what circumstances and why?
Is there a scenario where mixing two scripting languages can reduce execution time? (Is this situation realistic?) )
If a language is always faster than the other, is the speed difference large enough to be a factor in choosing a scripting language?
To answer these questions, we will compare the execution time of the 8 typical routines, which are written in both VBScript, JScript, and both (in combination, a scripting language as the primary language of an ASP page (the Basic language), which invokes an inline function written by another scripting language). These 8 routines are:
String flip (upside down),
Search for another string within a string,
Regular expression pattern matching,
Displacement operation,
Simple mathematical calculations,
Complex mathematical calculations,
Array initialization,
ADO recordset traversal.
Analysis method
Given that there are so many factors affecting Web application performance, and the real difficulty may also be to configure a fully controlled (also known as "unrealistic") test environment, the purpose of this paper is not to give the two language performance comparison of the exact measure of the difference, but to give a variety of programming programs under the performance of the relative advantages of reliable instructions.
That is to say, our goal is not to know that JScript's regular expression pattern-matching operations are 23% faster than VBScript's, and our main concern is whether there is such a difference, how much this difference is generally apparent, what the difference is, and why.
This article only gives summary (average) data. If you want to see more specific data, you can find the original test results in Data.xls. Data.xls can be downloaded from the back of this article.
The test is done on a desktop system, configured to: 400MHz Celeron processor, 128 MB RAM, operating system Windows Server (5.00.2195), and the Web server is running ASP 3.0 (Asp.dll 5.0.2180.1) IIS 5.0.2157.1. The version of the script engine (JScript and VBScript) is 5.1.0.4615. The system runs a minimal number of services during the test, and the minimum number remains unchanged to ensure the stability of the test environment as much as possible.
In addition, many tests are performed under two possible default scripting engine settings, considering that the default scripting engine settings for IIS can cause deviations from test results. In all tested scenarios, this factor does not affect the timing of execution and the size of the difference in execution results.
Testing Tools
Two test tool pages are written in VBScript (Default.asp) and JScript (default-js.asp) respectively. The two pages have the same function: Let the tester Select an ASP page and specify the number of times to execute the page, and record the cumulative execution time of 1 per thousand seconds (see figure below). (The executed page is called by the Server.Execute of the test Tools page).
"Figure 1"
Similarly, many test scenarios are tested with two test tools pages under different IIS default script engine settings, given that the script engine initialization may affect the execution time of the called page. As before, this factor in all tested scenarios does not affect the timing of execution and the size of the difference in execution results. (However, for Test records, even if the default scripting engine for IIS is set to JScript, the test tools page written in VBScript is slightly faster than the Test tool page written in JScript).
Performance Metrics
The performance metrics tested in this article are execution times. The execution time is rounded to the nearest millisecond value. If the Test Tool page executes a test page more than once (for example, 1000 Server.Execute calls), the start of the execution time begins at the end of the loop before the "for Loop" loop that surrounds the test page call.
The test tools page based on VBScript calculates the execution time with the timer () function, and the test tool page based on JScript calculates the execution time with the JScript Date object.
We selected eight different test routines (all the code used in the test is already available in the download zip file later in this article). If the language itself does not have a method or function, write a dedicated method.
1. String Flip: This test is done not only because it is a very representative operation, but because VBScript provides a built-in StrReverse () function and JScript does not have an equivalent function or method. This provides us with a very good mixed language programming test case. The string that was flipped in this test is "string reversal".
2. Search for another string in a string: VBScript and JScript themselves provide a way to implement the task. We use the InStr () function of VBScript and the IndexOf () method of JScript in the string "This is a sentence written for the sake of writing a sentence." Finds the starting position of the string "Ke" in the
3. Regular expression pattern matching: Although VBScript has recently joined regular expression support, this is still a good comparison test case. JScript provides a variety of string object methods that accept patterns that allow us to handle more flexibly, while VBScript is not so flexible and must be done within the bounds defined by the RegExp object. The test page contains a function that accepts the string "Regular Expression pattern Match" and the Regular expression "/(eg) |y|t{2,}/" and returns the total number of matches.
4. Displacement operations: JScript has bit operators and VBScript does not, this is a good comparison test case. The following actions will be performed on the page where this test will be performed: < < 5 and -14 > > 2.
5. Simple mathematical Calculations: The following calculations are performed: 18976.6754 + (-908.6) + 1475.211.
6. Complex mathematical calculations: The test page contains a function that calculates the distance (miles) between them based on the coordinates of the two points. The calculated expression for VBScript is:
Distance = Round ((69.1 * (LATA-LATB) ^2) + (69.1 * (Abs (Lnga)-abs (LNGB)) * Cos (latb/57.3)) ^2)), 1).
7. Array initialization: Both VBScript and JScript engines will create a temporary copy of the entire array as long as there is access to arrays of elements, which is also a good test case. In addition, the JScript array is also an object with many methods and properties, while the array in VBScript is just an array. This test initializes an array of 100,000 elements through a for loop, and each element is given the value of the loop counter.
8. ADO Recordset Traversal: The database used for this test is the Access2000 "Northwind" database, where the program uses the ADO Connection object to execute the SELECT * FROM Orders command to obtain an ADO recordset. The program uses two nested loops: the outer loop loops through the records, and the internal loops through all the fields of each record. This test case is good because JScript needs to instantiate a enumeration object to traverse the collection of objects, and VBScript only needs a for each ... The next loop can accomplish the same task.
The above 第一、三、四、六 several algorithms have a common feature: either one of the languages has a unique function, or in regular expression matching and distance computing, the difference between the two languages is very large enough to become a very meaningful mixed language programming test project. This gives us two additional scenarios for testing these algorithms: calling inline JScript functions in VBScript as the base language, and calling inline VBScript functions in the base language of JScript. Examples of test code are as follows (test scenario: String flip, in JScript as the base language, VBScript inline):
<% @Language =jscript% > < SCRIPT language= "VBScript" runat= "Server" > Function strrevvb (strparm) StrReverse ( Strparm) End Function </script > <% STRREVVB ("String reversal")% >
All other routines contain only the functionality provided by the language itself, which is tested only in pure VBScript and in pure JScript version of the code. In other words, for any case of mixed language programming rationality measured