allujyothirmayi / cloudsim

Automatically exported from code.google.com/p/cloudsim
0 stars 0 forks source link

Optimization of Cloudsim.runClockTick() #42

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What version of the product are you using? On what operating system?
CloudSim3.0

Please provide any additional information below.
Below is a snippet of code from the Cloudsim class
public static boolean runClockTick() {

...
    SimEntity ent;
    boolean queue_empty;
    int entities_size = entities.size();

    for (int i = 0; i < entities_size; i++) {
        ent = entities.get(i);
        if (ent.getState() == SimEntity.RUNNABLE) {
            ent.run();
        }
    }
...
}

Unless you are only accessing an ArrayList once, it is better to use an 
Iterator to iterate through the array list. Here is my proposed change:

public static boolean runClockTick() {

...
    Iterator<SimEntity> it = entities.iterator();
    while(it.hasNext()) {
        ent = it.next();
        if (ent.getState() == SimEntity.RUNNABLE) {
            ent.run();
        }
    }
...
}

Original issue reported on code.google.com by William....@gmail.com on 11 Nov 2012 at 4:22

GoogleCodeExporter commented 8 years ago
Note:
    SimEntity ent;
    boolean queue_empty;

still need to be in the changed version* For some reason I left them out. Here 
is what the final version should look like:

public static boolean runClockTick() {

...
    SimEntity ent;
    boolean queue_empty;
    Iterator<SimEntity> it = entities.iterator();
    while(it.hasNext()) {
        ent = it.next();
        if (ent.getState() == SimEntity.RUNNABLE) {
            ent.run();
        }
    }
...
}

Original comment by William....@gmail.com on 13 Nov 2012 at 4:42

GoogleCodeExporter commented 8 years ago
This can be solved for the next release. Thanks, William

Original comment by rodrigo.calheiros on 9 Apr 2013 at 11:49

GoogleCodeExporter commented 8 years ago

Original comment by rodrigo.calheiros on 29 Apr 2013 at 4:08

GoogleCodeExporter commented 8 years ago
Regression problem: This change may trigger concurrent access exceptions during 
simulation.

Original comment by rodrigo.calheiros on 29 Apr 2013 at 4:36