HTML and CSS Reference
In-Depth Information
4.1.2.4 Exploring Frameworks
Third party interfaces such as “Ajax libraries” make excellent targets for a few
learning tests. The learning tests provide neutral ground to play with a library, and
we get to try out the interfaces in a more free form than we probably would if
we simply dropped the framework right into the application. In fact, doing a little
bit of experimenting with a given framework can even influence the decision on
whether or not to use it in an application. Many libraries have lots of initial appeal,
but fail to live up to their expectations in practice. Exercising them in a sandboxed
environment allows us to get a better feel of using them, and we are free to push
them through hoops we know they will need to handle when introduced to a real
production environment. Again, performing this kind of experiment in structured
files rather than a console environment means we can refer to them at any point,
perhaps to compare a set of libraries that was tested.
4.2 Performance Tests
Another type of automated test that can teach us a whole lot are benchmarks that test
relative performance. Most problems can be solved in many ways, and sometimes
it is not obvious which solution is best. For example, as we will see in Chapter 7,
Objects and Prototypal Inheritance, there are different ways of creating JavaScript
objects, mainly the pseudo-classical way, using JavaScript's constructors, and the
functional approach, using closures. How do we choose which strategy to employ?
Personal preference usually plays a part in such choices, as does testability, flexibility,
and performance. Depending on the use case, the performance aspect can prove to
be very important.
4.2.1 Benchmarks and Relative Performance
Whenever we have two or more ways to solve a given problem, a benchmark can
indicate how one solution performs relative to alternatives; hence “relative perfor-
mance.” A benchmark is a very simple concept:
Create a new Date() .
Exercise the code alternative to measure.
Create a new Date() ; subtract the start date to find total time.
Repeat for all alternatives.
Compare results.
Exercising the code alternative to measure usually needs to be done many times
in a loop to improve accuracy of the measurement. Additionally, Windows XP and
 
 
Search WWH ::




Custom Search