According to 80-20 Rule: Look for that 20% of the code where your program spends 80% of it's time
e.g. The HTTP specification is a 100 page document that describes all possible HTTP requests that a web server must handle.Most of the HTTP requests that traverse through the web are very simple. They contain only a small subset of the possible HTTP headers that a request can possibly contain.
Since Microsoft and Netscape have a dominating share of the browser market, all you need to do is peek at the request headers sent by these two browsers. This is yet another manifestation of the 80-20 rule—20% of your possible inputs will occur 80% of the time. An efficient use of programmer resources is to tune those 20% of the request types that appear 80% of the time.
The HTTP Accept header is part of an HTTP request. It specifies what document formats are acceptable to the browser. The HTTP specification allows for the Accept header to have any combination of upper and lowercase. When you read a string token and want to determine if it is the Accept header, it is not enough to perform
We need to perform a case-sensitive string compare. We implemented a home-grown version for a casesensitive string-compare:
To be HTTP compliant, the correct action should be
However, memCaseCmp() is not cheap. It needs to uppercase both strings and then call memcmp(). This is where our domain expertise must come into play. Like we said, Microsoft and Netscape have a commanding share of the browser market. The Accept header they send happens to be "Accept:". This is only one of the many upper- and lowercase combination that HTTP allows, but it is the one we are going to receive 95% of the time, so it is the one we care about. The following test tries to take advantage of that:
In 95% of the inputs, the memcmp() test is going to succeed, and we will never call the more expensive memCaseCmp().
Search This BlogFeb 17, 200880-20 Rule
Subscribe to:
Post Comments
(
Atom
)
|
No comments :
Post a Comment