Saturday, March 31, 2012

Computer performance & Clock speed

Many people use clock speed as a measure of a computer’s total computing power, but that term can be very misleading for a couple of reasons.

The computer keeps all its devices synchronized by using its clock. This isn’t a regular clock—it’s a “clock in a chip,” which keeps highly accurate time and ticks much more rapidly than a wall clock. The faster the computer’s clock ticks, the more quickly the device can move on to a new task. The central processing unit  needs a certain number of clock ticks to  execute each of its instructions. Therefore, the faster the clock ticks (that is, the “clock speed”), the more instructions the CPU can execute per second.

 However, that’s not the end of the story. Different processors use different instruction sets, each of which can require a different number of ticks. That means different kinds of processors may execute different numbers of instructions per second, even if they have the same clock speed. You can use clock rate to compare two of the same kinds of processor (for example, a 2.93-gigahertz (GHz) Intel Pentium 4 and a 3.0-GHz Intel Pentium 4) but not as an accurate comparison between two processors of different types (for example, a 3.0-GHz Intel Pentium 4 and a 3.0-GHz AMD Athlon II).

Even if you could fgure out which processor executes more instructions per second, that figure alone doesn’t necessarily tell you which computer will be faster for your program. Many programs - most, in fact—are limited by factors other than sheer processor speed, including amount and speed of memory, disk space, network speed, graphics or floating-point processor speeds, and bus speed.

Many modern computers have multiple processors or multiple cores (execution areas within a processor), so they can perform more than one task at the same time. Whether the computer gets a significant beneft from multiple cores depends on whether the tasks it is performing can be easily split into separate pieces—and whether the program was written to take advantage of multi-core hardware. Many programs are limited by disk drive speed. Disk drives spin at anywhere from 3,000 RPM to 15,000 RPM (speeds between 4,200 RPM and 7,200 RPM are most typical), so the time it takes to read and write data can vary dramatically.

Which of these factors is most important for your application depends on what that application does. If your program uses a local database heavily, disk speed will be a big factor. If the database is on a remote server, then the speed of the server and the network’s speed are probably bigger performance factors for your application than the speed of your local CPU.

To get an idea of how well the program will run ahead of time, focus on the system’s overall performance, running a wide variety of tests rather than looking just at clock speed. To look at one set of tests in the most recent versions of Microsoft Windows, open the computer’s Start menu, right-click the Computer entry, and select Properties to see the basic information display shown in Figure:

To get more detail, click the Windows Experience Index link to see the display shown in Figure below. This display shows performance scores for several different system features.

By given figure, we can see that the graphics scores are the lowest, so this system may not give the best performance for high-end graphics programs, such as three-dimensional games. But the processor, RAM, and disk scores are higher, so this computer may be just fine for applications that are not graphics-intensive.The Windows Experience Index still doesn’t consider your program’s particular needs. For  example, it doesn’t know what kinds of instructions your program will perform the most (such as integer calculations, foating-point calculations, string operations, and so on) and it doesn’t consider network bandwidth, but at least it provides a reasonably consistent value that can help you compare different systems.

Friday, March 30, 2012

Laptops vs Notebooks vs Netbooks vs Tablets

A laptop is a computer that is intended to run anywhere as it is portable. Laptops have integrated screens and keyboards and run on batteries. Heavy use to some hardware such as GPU, DVD drives can quickly drain the batteries. Laptops have a touchpad, pointing stick, trackball, or other pointing device. Nowadays, we can add external devices like mouse, keyboard etc.

Notebooks are stripped-down laptops. They are thin and have relatively small screens and are ultra-light. They rarely have CD-ROM or DVD and also have very limited graphics capabilities. As notebooks doesn’t have external media (DVD, etc), they typically have integrated network connection hardware so one can load software on to them. Network hardware can be used to access the internet.

Netbooks are even more stripped down than notebooks. They typically have less powerful processors and are primarily used for networked applications as web browsers, where most of the processing happens on a remote server.

A tablet is similar to laptop that uses touch screen or stylus as its primary input device. Tablets may display virtual keyboards on their screens and may use handwriting recognition for text input.Lap

Sunday, March 4, 2012

WPF: Significance of x:Key attribute

Each object declared as resource must set x:Key property. This property will be used by another elements to access the resource. But for Style objects, there is an exception. Style objects that set the TargetType property do not need to set x:Key explicitly because it is set implicitly behind the scenes.

Scenario1: When x:Key is defined
<Style x:Key="myStyle" TargetType="Button">
      <Setter Property="Background" Value="Yellow"/>
In above example, x:Key property is used, so, style will be visible on Button, only when Style property is used explicitly on element, as shown in below snippet:
<Button Style="{StaticResource myStyle}" Width="60" Height="30" />

Scenario2:When x:Key is not defined
<Style TargetType="Button">
    <Setter Property="Background" Value="Yellow"/>
In above example, style will be applied by default on all the buttons (due to TargetType) as no x:Key is defined in Style resource. Code for the button is shown below:
<Button Name="btnShow" Width="60" Height="30" />

Saturday, March 3, 2012

WPF: StaticResource vs DynamicResource

Logical resources allow you to define objects in XAML, which are not part of visual tree but can be used in your user interface. One of the examples of logical resource is Brush, which is used to provide a color scheme. Generally those objects are defined as resource, which are used by multiple elements of the applications.

        <RadialGradientBrush x:Key="myGradientBrush">
            <GradientStop Color="Green" Offset="0"/>
            <GradientStop Color="Blue" Offset="2"/>

Now, above declared resource could be used as either static or dynamic resource. One point to remember is that, when using static resources, it should be first defined in XAML code, before it can be referred. Static and Dynamic resources can be used as:

<Grid Background="{StaticResource myGradientBrush}"></Grid>
<Grid Background="{DynamicResource myGradientBrush}"></Grid>

The difference between StaticResource and DynamicResource lies in how the resources are retrieved by the referencing elements. StaticResource are retrieved only once by the referencing element and used for entire life of the resource. On the other hand, DynamicResource are acquired every time the referenced object is used.
Putting it in simpler way, if the color property of RadialGradientBrush is changed in code to Orange and Pink, then it will reflect on elements only when resource is used as DynamicResource. Below is the code to change the resource in code:

RadialGradientBrush radialGradientBrush = new RadialGradientBrush( Colors.Orange, Colors.Pink);
this.Resources["myGradientBrush"] = radialGradientBrush;

The demerit of DynamicResource is that it reduces application performance because resources are retrieved every time they are used. The best practice is to StaticResource use until there is a specific reason to use DynamicResource.