Measuring performance changes from applying 4837946 patch

Brian Burkhalter brian.burkhalter at
Tue Jun 4 17:44:39 UTC 2013

Hi Sergey,

On Jun 4, 2013, at 6:49 AM, Sergey Kuksenko wrote:

> could you show your benchmark?

Please see code below.

> My quick experiments show that current Karatsuba threshold is quite reasonable.

I hope that you are correct. I would like to know why I am seeing such different numbers.



 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
 * This code is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 only, as published by
 * the Free Software Foundation. Oracle designates this particular file as
 * subject to the "Classpath" exception as provided by Oracle in the LICENSE
 * file that accompanied this code.
 * This code is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more
 * details (a copy is included in the LICENSE file that accompanied this code).
 * You should have received a copy of the GNU General Public License version 2
 * along with this work; if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or
 * visit if you need additional information or have any
 * questions.
package corelibs;

import java.math.BigInteger;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.BenchmarkType;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;

public class BigIntegerBench {

    static final int BITS_KARATSUBA = 1600;
    static final int BITS_TOOM_COOK = 2400;
    static final int BITS_KARATSUBA_SQUARE = 2880;
    static final int BITS_TOOM_COOK_SQUARE = 4480;

    static final int BITS_GENERIC = 1600;

    public static class BenchmarkState {
        Random random = new Random(42L);
        BigInteger genericFactor1 = new BigInteger(BITS_GENERIC + 1, random);
        BigInteger genericFactor2 = new BigInteger(BITS_GENERIC + 400, random);

    public BigInteger multiplyStandardGeneric(BenchmarkState state) {
        return state.genericFactor1.multiply_standard(state.genericFactor2);

    public BigInteger multiplyKaratsubaGeneric(BenchmarkState state) {
        return state.genericFactor1.multiply_karatsuba(state.genericFactor2);

    public BigInteger multiplyToomCookGeneric(BenchmarkState state) {
        return state.genericFactor1.multiply_toom_cook(state.genericFactor2);

More information about the core-libs-dev mailing list