/**
 * Copyright 2016 Palantir Technologies
 *
 * Licensed under the BSD-3 License (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.palantir.atlasdb.performance.benchmarks;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Warmup;

import com.google.common.collect.Multimap;
import com.palantir.atlasdb.keyvalue.api.Cell;
import com.palantir.atlasdb.performance.benchmarks.table.RegeneratingTable;

@State(Scope.Benchmark)
public class KvsDeleteBenchmarks {

    private Object doDelete(RegeneratingTable<Multimap<Cell, Long>> table) {
        table.getKvs().delete(table.getTableRef(), table.getTableCells());
        return table.getTableCells();
    }

    @Benchmark
    @Warmup(time = 1, timeUnit = TimeUnit.SECONDS)
    @Measurement(time = 6, timeUnit = TimeUnit.SECONDS)
    public Object singleDelete(RegeneratingTable.KvsRowRegeneratingTable table) {
        return doDelete(table);
    }

    @Benchmark
    @Warmup(time = 3, timeUnit = TimeUnit.SECONDS)
    @Measurement(time = 22, timeUnit = TimeUnit.SECONDS)
    public Object batchDelete(RegeneratingTable.KvsBatchRegeneratingTable table) {
        return doDelete(table);
    }

}

@@ -898,16 +898,64 @@
 armup;%0A%0A
+import com.google.common.collect.ImmutableList;%0A
 import c
@@ -1036,16 +1036,152 @@
 i.Cell;%0A
+import com.palantir.atlasdb.keyvalue.api.RangeRequest;%0Aimport com.palantir.atlasdb.performance.benchmarks.table.ConsecutiveNarrowTable;%0A
 import c
@@ -1514,482 +1514,1475 @@
     
-@Benchmark%0A    @Warmup(time = 1, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 6, timeUnit = TimeUnit.SECONDS)%0A    public Object singleDelete(RegeneratingTable.KvsRowRegeneratingTable table) %7B%0A        return doDelete(table);%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(time = 3, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 22, timeUnit = TimeUnit.SECONDS)%0A    public Object batchDelete(RegeneratingTable.KvsBatchRegeneratingTable table) %7B%0A        return doDelete(table
+private Object doDeleteRange(ConsecutiveNarrowTable table, int numBatches) %7B%0A        Iterable%3CRangeRequest%3E rangeRequests;%0A        if (numBatches == 1) %7B%0A            rangeRequests = ImmutableList.of(RangeRequest.all());%0A        %7D else %7B%0A            rangeRequests = table.getRangeRequests(1, table.getNumRows() / numBatches);%0A        %7D%0A        rangeRequests.forEach(rangeRequest -%3E table.getKvs().deleteRange(table.getTableRef(), rangeRequest));%0A%0A        return rangeRequests;%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(time = 1, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 6, timeUnit = TimeUnit.SECONDS)%0A    public Object singleDelete(RegeneratingTable.KvsRowRegeneratingTable table) %7B%0A        return doDelete(table);%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(time = 3, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 22, timeUnit = TimeUnit.SECONDS)%0A    public Object batchDelete(RegeneratingTable.KvsBatchRegeneratingTable table) %7B%0A        return doDelete(table);%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(time = 1, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 30, timeUnit = TimeUnit.SECONDS)%0A    public Object batchRangeDelete(ConsecutiveNarrowTable.CleanNarrowTable table) %7B%0A        return doDeleteRange(table, 4);%0A    %7D%0A%0A    @Benchmark%0A    @Warmup(time = 1, timeUnit = TimeUnit.SECONDS)%0A    @Measurement(time = 30, timeUnit = TimeUnit.SECONDS)%0A    public Object allRangeDelete(ConsecutiveNarrowTable.CleanNarrowTable table) %7B%0A        return doDeleteRange(table, 1
 );%0A 

add benchmarks for deleteRange