TODO terribly inefficient
964740
function getRootNode (host) {
  if (isRootNode(host)) {
    return host;
  }

  if (!host.parentNode) {
    return;
  }

  return getRootNode(host.parentNode);
}
270027
public long approximateDataSize() {
        long result = 0;
        for (Map.Entry<String, DataNode> entry : nodes.entrySet()) {
            DataNode value = entry.getValue();
            synchronized (value) {
                result += entry.getKey().length();
                result += (value.data == null ? 0
                        : value.data.length);
            }
        }
        return result;
    }
752390
private double update(double[][] data, double T, int k, double[][] centroids, double[][] posteriori, double[] priori) {
        int n = data.length;
        int d = data[0].length;

        double D = 0.0;
        double H = 0.0;

        int iter = 0;
        double currentDistortion = Double.MAX_VALUE;
        double newDistortion = Double.MAX_VALUE / 2;
        while (iter < 100 && currentDistortion > newDistortion) {
            currentDistortion = newDistortion;

            D = Double.NaN;
            H = 0.0;

            if (tasks != null) {
                try {
                    D = 0.0;
                    for (UpdateThread t : tasks) {
                        t.k = k;
                        t.T = T;
                    }
                    
                    for (UpdateThread t : MulticoreExecutor.run(tasks)) {
                        D += t.D;
                        H += t.H;
                    }
                } catch (Exception ex) {
                    logger.error("Failed to run Deterministic Annealing on multi-core", ex);

                    D = Double.NaN;
                }
            }

            if (Double.isNaN(D)) {
                D = 0.0;
                double[] dist = new double[k];

                for (int i = 0; i < n; i++) {
                    double p = 0.0;

                    for (int j = 0; j < k; j++) {
                        dist[j] = Math.squaredDistance(data[i], centroids[j]);
                        posteriori[i][j] = priori[j] * Math.exp(-dist[j] / T);
                        p += posteriori[i][j];
                    }

                    double r = 0.0;
                    for (int j = 0; j < k; j++) {
                        posteriori[i][j] /= p;
                        D += posteriori[i][j] * dist[j];
                        r += -posteriori[i][j] * Math.log(posteriori[i][j]);
                    }
                    H += r;
                }
            }
            
            for (int i = 0; i < k; i++) {
                priori[i] = 0;
                for (int j = 0; j < n; j++) {
                    priori[i] += posteriori[j][i];
                }
                priori[i] /= n;
            }

            boolean parallel = false;
            if (ctasks != null) {
                try {
                    for (CentroidThread t : ctasks) {
                        t.k = k;
                    }
                    
                    MulticoreExecutor.run(ctasks);
                    parallel = true;
                } catch (Exception ex) {
                    logger.error("Failed to run Deterministic Annealing on multi-core", ex);

                    parallel = false;
                }
            }

            if (!parallel) {
                for (int i = 0; i < k; i++) {
                    Arrays.fill(centroids[i], 0.0);
                    for (int j = 0; j < d; j++) {
                        for (int m = 0; m < n; m++) {
                            centroids[i][j] += data[m][j] * posteriori[m][i];
                        }
                        centroids[i][j] /= (n * priori[i]);
                    }
                }
            }

            newDistortion = D - T * H;
            iter++;
        }

        logger.info(String.format("Deterministic Annealing clustering entropy after %3d iterations at temperature %.4f and k = %d: %.5f (soft distortion = %.5f )%n", iter, T, k / 2, H, D));

        return currentDistortion;
    }
227911
@Override
    protected void doPerform() {
        org.openqa.selenium.Keys seleniumKeys = org.openqa.selenium.Keys.getKeyFromUnicode(keys.getKeyCode());
        if (isSourceDocumentRoot()) {
            keyboard().pressKey(seleniumKeys);
        } else {
            getActions().keyDown(getFirstElement(), seleniumKeys).perform();
        }
    }
703272
void increment() {
        long id = rand.nextInt(config.tuples);
        long toIncrement = rand.nextInt(5); // 0 - 4

        try {
            client.callProcedure(new CMCallback(), "Increment", toIncrement, id);
        }
        catch (IOException e) {
            // This is not ideal error handling for production, but should be
            // harmless in a benchmark like this
            try { Thread.sleep(50); } catch (Exception e2) {}
        }
    }
537472
private static void compute(int[] in, int[] out, int width, int height, int radius)
    {
        final int widthMinus1 = width - 1;
        final int tableSize = 2 * radius + 1;
        final int[] divide = new int[Constant.UNSIGNED_BYTE * tableSize];

        for (int i = 0; i < Constant.UNSIGNED_BYTE * tableSize; i++)
        {
            divide[i] = i / tableSize;
        }

        int inIndex = 0;
        for (int y = 0; y < height; y++)
        {
            compute(in, out, y, inIndex, divide, width, widthMinus1, height, radius);
            inIndex += width;
        }
    }
149084
function(){
        var h=this.maxY-this.minY;
        var d=this.maxZ-this.minZ;
        return 2*((this.maxX-this.minX)*(h+d)+h*d);
    }
989917
function initializeWithEval() {
  var dbTest = new loki('perfInsertWithEval');

  var start, end, totalTime;
  var totalTimes = [];
  var totalMS = 0.0;

  var coll = dbTest.addCollection('samplecoll',
    {
      indices: ['customId'],
      asyncListeners: false,
      disableChangesApi: true,
      transactional: false,
      clone: false
    }
  );

  var dv = coll.addDynamicView('test');
  dv.applyFind({'customId': {'$lt': arraySize/4 }});

  for (var idx=0; idx < arraySize; idx++) {
    var v1 = genRandomVal();
    var v2 = genRandomVal();

    start = performance.now();
    coll.insert({
      customId: idx,
      val: v1,
      val2: v2,
      val3: "more data 1234567890"
    });
    end = performance.now() - start;
    totalTimes.push([0, end * 1e6]);
  }

  for(idx=0; idx < totalTimes.length; idx++) {
    totalMS += totalTimes[idx][0] * 1e3 + totalTimes[idx][1]/1e6;
  }

  totalMS = totalMS.toFixed(2);
  var rate = arraySize * 1000 / totalMS;
  rate = rate.toFixed(2);
  trace("load (insert with dynamic view registered) : " + totalMS + "ms (" + rate + ") ops/s");
}
867004
static function optimizeFunction( $useComments, &$php, $tpl, &$node, &$resourceData )
    {
        $ret = 0;
        /* Just run the optimizer over all parameters */
        if ( isset( $node[3] ) and is_array( $node[3] ) )
        {
            foreach ( $node[3] as $key => $parameter )
            {
                $ret = $ret | eZTemplateOptimizer::optimizeVariable( $useComments, $php, $tpl, $node[3][$key], $resourceData );
            }
        }
        return $ret;
    }
641799
function lazyDo(fn, timeOut, doName, obj) {
  var sto = null;

  if (!obj) {
    obj = window;
  }
  if (timeOut == null) {
    timeOut = 25;
  }

  //If before the implementation of the operation has not exceeded the time,then make it cancel.
  if (doName && obj[doName]) {
    clearTimeout(obj[doName]);
  }

  //Delay for a period of time to perform the operation.
  sto = setTimeout(function () {
    fn.call(obj);
  }, timeOut);

  if (doName) {
    obj[doName] = sto;
  }

  return sto;
}
1096065
@Override
    public int drainTo(Collection<? super T> c, int maxElements) {

        //TODO- The elements aren't added to the given collection...

        if (c == null)
            throw new NullPointerException();
        if (c == this)
            throw new IllegalArgumentException();

        int n = Math.min(maxElements, size());

        int numRemaining = n;

        synchronized (this) {
            synchronized (lock) {
                //Retrieve and remove at most n elements from the expedited buffer and add them to the passed collection
                for (int i = 0; i < n; i++) {
                    T retrieved = expeditedExtract();
                    numRemaining = n - i;
                    if (retrieved != null) {
                        numberOfUsedExpeditedSlots.getAndDecrement();
                        //TODO if expedited is added for put or offer with timeout add notification here
                    } else {
                        break; //retrieved is null so nothing left in the expedited buffer, move on to the main buffer
                    }
                }
                //Retrieve and remove at most numRemaining elements and add them to the passed collection
                for (int i = 0; i < numRemaining; i++) {
                    T retrieved = extract();
                    numberOfUsedSlots.getAndDecrement();
                    if (retrieved != null) {
                        notifyPut_();
                    }
                }
            }
        }
        return n;
    }
284560
function worst(row, rowFixedLength, ratio) {
    var areaMax = 0;
    var areaMin = Infinity;

    for (var i = 0, area, len = row.length; i < len; i++) {
        area = row[i].getLayout().area;
        if (area) {
            area < areaMin && (areaMin = area);
            area > areaMax && (areaMax = area);
        }
    }

    var squareArea = row.area * row.area;
    var f = rowFixedLength * rowFixedLength * ratio;

    return squareArea
        ? mathMax(
            (f * areaMax) / squareArea,
            squareArea / (f * areaMin)
        )
        : Infinity;
}
36512
function toDouble( frac ) {
	var sum = 0;
	var i;
	for ( i = 0; i < frac.length; i++ ) {
		if ( frac[ i ] === '1' ) {
			sum += pow( 2, -(i+1) );
		}
	}
	return sum;
}
692736
@SuppressWarnings("unchecked")
   private static <T> T[] finishToArray(T[] r, Iterator<?> it) {
      int i = r.length;
      while (it.hasNext()) {
         int cap = r.length;
         if (i == cap) {
            int newCap = cap + (cap >> 1) + 1;
            // overflow-conscious code
            if (newCap - MAX_ARRAY_SIZE > 0)
               newCap = hugeCapacity(cap + 1);
            r = Arrays.copyOf(r, newCap);
         }
         r[i++] = (T)it.next();
      }
      // trim if overallocated
      return (i == r.length) ? r : Arrays.copyOf(r, i);
   }
74450
@Override
    public int drainTo(Collection<E> collection) {
        int size = queue.drainTo(collection);
        addCapacity(-size);
        return size;
    }
670915
T clipInput(T input, T output) {
		double ratioInput = input.width/(double)input.height;
		double ratioOutput = output.width/(double)output.height;

		T a = input;

		if( ratioInput > ratioOutput ) { // clip the width
			int width = input.height*output.width/output.height;
			int x0 = (input.width-width)/2;
			int x1 = x0 + width;

			clipped = input.subimage(x0,0,x1,input.height, clipped);
			a = clipped;
		} else if( ratioInput < ratioOutput ) { // clip the height
			int height = input.width*output.height/output.width;
			int y0 = (input.height-height)/2;
			int y1 = y0 + height;

			clipped = input.subimage(0,y0,input.width,y1, clipped);
			a = clipped;
		}

		return a;
	}
409814
def do_less_expensive_things(number):
    
    result = yield batch_accumulate(1000, expensive(number))
    total = reduce(add, result, 0)
    log.msg("only for {}: {}".format(number, total))
    defer.returnValue(total)