import java.util.Random; import java.util.function.LongFunction; import java.util.function.Consumer; import java.util.function.LongFunction; import java.util.Arrays; public class Main { public static class BenchUtils { public static Stat bench(LongFunction generator, Consumer runner, int rep) { long sum = 0, max = 0, min = Long.MAX_VALUE; for(int i = 0;i < rep;i++){ T t = generator.apply(i*1000000009L); long S = System.nanoTime(); runner.accept(t); long G = System.nanoTime(); sum += G-S; max = Math.max(max, G-S); min = Math.min(min, G-S); } return new Stat(sum, sum/rep, max, min); } } static class TestCase { long[] a, b; public TestCase(long[] a, long[] b) { this.a = a; this.b = b; } } public static class Stat { public long sum; public long average; public long max; public long min; public Stat(long sum, long average, long max, long min) { this.sum = sum; this.average = average; this.max = max; this.min = min; } @Override public String toString() { return "Stat [sum=" + sum + ", average=" + average + ", max=" + max + ", min=" + min + "]"; } } public static class U { public static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } } public static void main(String[] args) { LongFunction generator = (o) -> { Random gen = new Random(o*1000000009L); long[] a = new long[1000000]; long[] b = new long[1000000]; for(int i = 0;i < a.length;i++)a[i] = gen.nextInt(1000000007); for(int i = 0;i < b.length;i++)b[i] = gen.nextInt(1000000007); return new TestCase(a, b); }; // divide % U.tr(BenchUtils.bench(generator, (t) -> { int mod = 1000000007; for(int i = 0;i < t.a.length;i++){ t.a[i] += t.b[i]; } for(int i = 0;i < t.a.length;i++){ t.a[i] %= mod; } }, 10)); // concat % U.tr(BenchUtils.bench(generator, (t) -> { int mod = 1000000007; for(int i = 0;i < t.a.length;i++){ t.a[i] += t.b[i]; t.a[i] %= mod; } }, 10)); // concat %2 U.tr(BenchUtils.bench(generator, (t) -> { int mod = 1000000007; for(int i = 0;i < t.a.length;i++){ t.a[i] = (t.a[i] + t.b[i]) % mod; } }, 10)); // divide - U.tr(BenchUtils.bench(generator, (t) -> { int mod = 1000000007; for(int i = 0;i < t.a.length;i++){ t.a[i] += t.b[i]; } for(int i = 0;i < t.a.length;i++){ if(t.a[i] >= mod)t.a[i] -= mod; } }, 10)); // concat - U.tr(BenchUtils.bench(generator, (t) -> { int mod = 1000000007; for(int i = 0;i < t.a.length;i++){ t.a[i] += t.b[i]; if(t.a[i] >= mod)t.a[i] -= mod; } }, 10)); } }