zoukankan      html  css  js  c++  java
  • Effective Java 55 Optimize judiciously

    Principle

    1. Strive to write good programs rather than fast ones.
    2. Strive to avoid design decisions that limit performance.

      Design components:

      1. APIs
      2. Wire-level protocols
      3. Persistent data formats
    3. Consider the performance consequences of your API design decisions.
      1. Make a public type mutable may require a lot of needless defensive coping(Item 39).
      2. Using inheritance in a public class where composition would have been appropriate ties the class forever to its superclass, which can place artificial limits on the performance of the subclass(Item 16).
      3. Using an implementation type rather than an interface in an API ties you to a specific implementation, even though faster implementations may be written in the future(Item 52).
    4. It is a very bad idea to warp an API to achieve good performance.  

    Summary

    Do not strive to write fast programs—strive to write good ones; speed will follow. Do think about performance issues while you're designing systems and especially while you're designing APIs, wire-level protocols, and persistent data formats. When you've finished building the system, measure its performance. If it's fast enough, you're done. If not, locate the source of the problems with the aid of a profiler, and go to work optimizing the relevant parts of the system. The first step is to examine your choice of algorithms: no amount of low level optimization can make up for a poor choice of algorithm. Repeat this process as necessary, measuring the performance after every change, until you're satisfied.

       

  • 相关阅读:
    贪心算法1000
    贪心算法1006
    1012
    贪心算法1016
    贪心算法1001
    贪心算法1004
    Java作业1
    指针数组与数组指针的区别
    Java 中对类进行排序的方法(转)
    java习题1
  • 原文地址:https://www.cnblogs.com/haokaibo/p/optimize-judiciously.html
Copyright © 2011-2022 走看看