Search in sources :

Example 1 with UBJsonReader

use of com.badlogic.gdx.utils.UBJsonReader in project libgdx by libgdx.

the class UBJsonTest method performanceTest.

private void performanceTest() throws Exception {
    Gdx.app.log("UBJsonTest", "--- performanceTest ---");
    long start = System.currentTimeMillis();
    UBJsonWriter uw = new UBJsonWriter(Gdx.files.external(fn).write(false, 8192));
    uw.object();
    uw.set("0floats", new float[] {});
    uw.set("3floats", new float[] { 1, 2, 3.456789f });
    uw.set("xfloats", new float[] { Float.MIN_VALUE, Float.MAX_VALUE, Float.NaN, Float.NEGATIVE_INFINITY });
    uw.set("double", 0.000000000000000000001);
    uw.set("long", Long.MAX_VALUE);
    uw.array("arr");
    uw.object().pop();
    for (int i = 0; i < 50000; i++) {
        uw.value(true).value(false).value(true);
        uw.value((byte) 254);
        uw.value((byte) (-2));
        uw.value((short) -32000);
        uw.value((int) -123456);
        uw.value((long) (-((1 << 63) - 1)));
        uw.value(longString);
    }
    uw.pop();
    uw.pop();
    uw.close();
    Gdx.app.log("UBJsonTest", "Writing the test file took " + (System.currentTimeMillis() - start) + "ms");
    Gdx.app.log("UBJsonTest", "File size is " + Gdx.files.external(fn).length());
    UBJsonReader ur = new UBJsonReader();
    ur.oldFormat = false;
    start = System.currentTimeMillis();
    ur.parse(Gdx.files.external(fn));
    Gdx.app.log("UBJsonTest", "Parsing the test file took " + (System.currentTimeMillis() - start) + "ms");
}
Also used : UBJsonWriter(com.badlogic.gdx.utils.UBJsonWriter) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader)

Example 2 with UBJsonReader

use of com.badlogic.gdx.utils.UBJsonReader in project libgdx by libgdx.

the class UBJsonTest method create.

@Override
public void create() {
    try {
        UBJsonWriter uw = new UBJsonWriter(Gdx.files.external(fn).write(false));
        uw.object();
        uw.set(longString, longString);
        uw.set("0floats", new float[] {});
        uw.set("3floats", new float[] { 1, 2, 3.456789f });
        uw.set("xfloats", new float[] { Float.MIN_VALUE, Float.MAX_VALUE, Float.NaN, Float.NEGATIVE_INFINITY });
        uw.set("double", 0.000000000000000000001);
        uw.set("long", Long.MAX_VALUE);
        uw.set("3bytes", new byte[] { (byte) 1, (byte) 2, (byte) 3 });
        uw.set("3shorts", new short[] { (short) 1, (short) 2, (short) 3 });
        uw.set("3ints", new int[] { 1, 2, 3 });
        uw.set("3long", new long[] { 1l, 2l, 3l });
        uw.set("3double", new double[] { 1, 2, 3.456789 });
        uw.set("3char", new char[] { 'a', 'b', 'c' });
        uw.set("3strings", new String[] { "", "a", "abc" });
        uw.array("arr");
        uw.object().pop();
        uw.value(true).value(false).value(true);
        uw.value((byte) 254);
        uw.value((byte) (-2));
        uw.value((short) -32000);
        uw.value((int) -123456);
        uw.value((long) (-((1 << 63) - 1)));
        uw.pop();
        uw.pop();
        uw.close();
        UBJsonReader ur = new UBJsonReader();
        ur.oldFormat = false;
        JsonValue v = ur.parse(Gdx.files.external(fn));
        Gdx.app.log("UBJsonTest", "result = \n" + v.toString());
        performanceTest();
        Gdx.app.log("UBJsonTest", "Test succeeded");
    } catch (Throwable t) {
        Gdx.app.error("UBJsonTest", "Test failed", t);
    }
}
Also used : UBJsonWriter(com.badlogic.gdx.utils.UBJsonWriter) JsonValue(com.badlogic.gdx.utils.JsonValue) UBJsonReader(com.badlogic.gdx.utils.UBJsonReader)

Aggregations

UBJsonReader (com.badlogic.gdx.utils.UBJsonReader)2 UBJsonWriter (com.badlogic.gdx.utils.UBJsonWriter)2 JsonValue (com.badlogic.gdx.utils.JsonValue)1