|
| 1 | +package org.apache.sysds.performance.frame; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | + |
| 5 | +import org.apache.sysds.common.Types.ValueType; |
| 6 | +import org.apache.sysds.performance.compression.APerfTest; |
| 7 | +import org.apache.sysds.performance.generators.ConstFrame; |
| 8 | +import org.apache.sysds.performance.generators.IGenerate; |
| 9 | +import org.apache.sysds.runtime.frame.data.FrameBlock; |
| 10 | +import org.apache.sysds.runtime.frame.data.columns.Array; |
| 11 | +import org.apache.sysds.runtime.transform.encode.EncoderFactory; |
| 12 | +import org.apache.sysds.runtime.transform.encode.MultiColumnEncoder; |
| 13 | +import org.apache.sysds.test.TestUtils; |
| 14 | + |
| 15 | +public class Transform extends APerfTest<Object, FrameBlock> { |
| 16 | + |
| 17 | + private final int k; |
| 18 | + private final String spec; |
| 19 | + |
| 20 | + public Transform(int N, IGenerate<FrameBlock> gen, int k, String spec) { |
| 21 | + super(N, gen); |
| 22 | + this.k = k; |
| 23 | + this.spec = spec; |
| 24 | + FrameBlock in = gen.take(); |
| 25 | + System.out.println("Transform Encode Perf: rows: " + in.getNumRows() + " schema:" + Arrays.toString(in.getSchema())); |
| 26 | + System.out.println(spec); |
| 27 | + } |
| 28 | + |
| 29 | + public void run() throws Exception { |
| 30 | + execute(() -> te(), () -> clear(), "Normal"); |
| 31 | + execute(() -> tec(), () -> clear(), "Compressed"); |
| 32 | + execute(() -> te(), () -> clear(), "Normal"); |
| 33 | + execute(() -> tec(), () -> clear(), "Compressed"); |
| 34 | + } |
| 35 | + |
| 36 | + private void te(){ |
| 37 | + FrameBlock in = gen.take(); |
| 38 | + MultiColumnEncoder enc = EncoderFactory.createEncoder(spec, in.getNumColumns()); |
| 39 | + enc.encode(in, k); |
| 40 | + ret.add(null); |
| 41 | + } |
| 42 | + |
| 43 | + private void tec(){ |
| 44 | + FrameBlock in = gen.take(); |
| 45 | + MultiColumnEncoder enc = EncoderFactory.createEncoder(spec, in.getNumColumns()); |
| 46 | + enc.encode(in, k, true); |
| 47 | + ret.add(null); |
| 48 | + } |
| 49 | + |
| 50 | + private void clear(){ |
| 51 | + clearRDCCache(gen.take()); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + protected String makeResString() { |
| 56 | + return ""; |
| 57 | + } |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * Forcefully clear recode cache of underlying arrays |
| 62 | + */ |
| 63 | + public void clearRDCCache(FrameBlock f){ |
| 64 | + for(Array<?> a : f.getColumns()) |
| 65 | + a.setCache(null); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + public static void main(String[] args) throws Exception { |
| 70 | + for(int i = 1; i < 100; i *= 10){ |
| 71 | + |
| 72 | + FrameBlock in = TestUtils.generateRandomFrameBlock(100000 * i , new ValueType[]{ValueType.UINT4}, 32); |
| 73 | + System.out.println(Arrays.toString(in.getColumnNames())); |
| 74 | + ConstFrame gen = new ConstFrame(in); |
| 75 | + // passthrough |
| 76 | + new Transform(300, gen, 16, "{}").run(); |
| 77 | + new Transform(300, gen, 16, "{ids:true, recode:[1]}").run(); |
| 78 | + new Transform(300, gen, 16, "{ids:true, bin:[{id:1, method:equi-width, numbins:4}]}").run(); |
| 79 | + new Transform(300, gen, 16, "{ids:true, bin:[{id:1, method:equi-width, numbins:4}], dummycode:[1]}").run(); |
| 80 | + new Transform(300, gen, 16, "{ids:true, hash:[1], K:10}").run(); |
| 81 | + new Transform(300, gen, 16, "{ids:true, hash:[1], K:10, dummycode:[1]}").run(); |
| 82 | + } |
| 83 | + |
| 84 | + System.exit(0); // forcefully stop. |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments