Skip to content

Instantly share code, notes, and snippets.

@s-u
Last active January 15, 2016 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-u/4efb284e3c15c6a2db16 to your computer and use it in GitHub Desktop.
Save s-u/4efb284e3c15c6a2db16 to your computer and use it in GitHub Desktop.
Java JSON data frame test example
// simple test case for generating a test data frame in Java in JSON and native form
// uses Java Jsonx API, e.g., compile with -cp javax.json-api-1.0.jar:javax.json-1.0.4.jar
import javax.json.*;
public class A {
public static int n = 1000000;
public static void main(String[] main) {
JsonObjectBuilder ob = Json.createObjectBuilder();
JsonArrayBuilder b = Json.createArrayBuilder();
for (int i = 0; i < n; i++) b.add(i/5.);
ob.add("V1", b);
b = Json.createArrayBuilder();
for (int i = 0; i < n; i++) b.add("X"+ (i % 10));
ob.add("V2", b);
JsonObject model = ob.build();
JsonWriter jsonWriter = Json.createWriter(System.out);
jsonWriter.writeObject(model);
jsonWriter.close();
}
public static Object[] direct() {
double d[] = new double[n];
for (int i = 0; i < n; i++) d[i] = i/5.;
String s[] = new String[n];
for (int i = 0; i < n; i++) s[i] = "X" + (i % 10);
return new Object[] { d, s };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment