Big performance issue or something wrong in my code ?

edited October 2014 in Questions about Code

Hello everybody

I wanted to make a small test in order to check Processing perfomances compared to something else i am also learning (xojo , "real basic").

So basically my test consist of loading very simple txt file containing about 4000 lines of random characters (likes: "498e4g6q4c4r74u4olp4trfe4zd5dg44" ) each lines are of the same length. and then I want to display these line in a textarea (I am using G4P library for this)

I encounter two problems :

it takes ages to execute. I have tried to reduce the number of lines to load but even with 1000 it takes something like 5 minutes before displaying anything.

So I am wondering if there is something wrong in my (I guess that's most likely the case :) ) or is processing just not the right language for doing these kind of things ?

here is my code :

    //import g4p_controls.*;
    String txtfile[] = loadStrings("c:\\list.txt"); 
    String[] lines;
    void setup() { 
      size(800, 650);

    void draw() {

      for (int i=0; i < txtfile.length; i++) {
        lines = split(txtfile[i], ENTER);
       // textarea1.appendText( i + " > " + lines);
         println( lines + " ");

Oh an other thing : instead of the lines I should see from my txt file it displays things like "[Ljava.lang.String;@78b25336 " I don't know why .


  • Answer ✓

    Some things:

    • Move loadStrings() to setup(). Here, it works because you use an absolute path, but if you want to load a file from the data folder in the sketch folder, as we usually do in Processing, you need to do this in setup().
    • In Java, it is simpler to use forward slashes as path separators, as there is no need to double them.
    • Why do you append a space to your array? It won't be visible, and that's the thing making a cryptic output. Processing's println() is smart enough to print out arrays.
    • Processing isn't designed for extensive output to the console. That's why it is slow, and can even crash for large output there...
  • Answer ✓

    The G4P textarea is not designed to append 4000 lines of text show quickly and will seriously affect the overall performance.

    Be wary of speed comparison tests it is difficult to get consistent results, especially if you are using disk input/output and console output because there are many things outside the control of the language that can affect performance.


    When you use println to display the value of an object it uses the toString() method to decide what to display. If the object's class has no toString method then it uses the one in the Object class. Java treats arrays as objects so the above line indicates that it is a single dimension String array stored at the address 78bb25336 (hexadecimal)

  • Thanks a lot for your answer , understand better now

  • Answer ✓

    Java treats arrays as objects.

    Actually, arrays are indeed objects. But it's the only 1 w/o a formal class and uses [] for access! :-B

Sign In or Register to comment.