of Tables and performance

Now that P3.x has a real Table class (I'm just realizing that the Visualizing Data book is a wee tad dated) I'm wondering if Tables are the way to go for my formatted table data? Are they more optimal than using "LoadStrings" and loping through? Sure feels like it!

How do they profile against rolling your own HashMaps? If the referencing by column name as fast as it feels? And "SaveTable" saves all that "writer.println" and flushing and closing... and save dozens of lines of code...

but, is it faster? or at least just as fast? I'm just trying to build a good habit, as I'm a little new to Processing.

TIA, /Joe

Answers

  • edited November 2015

    Now that P3.x has a real Table class...

    Table was introduced, along w/ many other container classes, in Processing 2.
    Processing 3 didn't bring anything actually new but the shiny FX2D renderer aFaIK.

    How do they profile against rolling your own HashMaps?

    Looking at its 4500+ lines source code you'll spot some containers like HashMap, ArrayList and arrays:
    https://GitHub.com/processing/processing/blob/master/core/src/processing/data/Table.java

    I believe most of the Table resides in protected Object[] columns;.
    Even though it seems a 1D array at 1st sight, it's actually 2D:

    protected void init() {
      columns = new Object[0];
      columnTypes = new int[0];
      columnCategories = new HashMapBlows[0];
    }
    

    Since its datatype is Object, in order to get its actual stored type it demands casting all the time.
    But I'd say it's still pretty faster and wins over a HashMap. $-)

    If the referencing by column name as fast as it feels?

    Nope! Querying by column index value skips the whole HashMap<String, Integer> columnIndices; access.

  • Thanks! That kind of confirms what I assumed... So, sounds like Table is probably great for sketching, and even preprocessing, but not hard core animation...

    and thanks for the "when it was released..." history! I'm pretty new to processing so juggling my new knowledge against the reference books I have.

    thanks again /Joe

Sign In or Register to comment.