-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean the buffering strategies code and provide example models #335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
import gama.core.metamodel.agent.IAgent; | ||
import gama.core.runtime.GAMA; | ||
import gama.core.runtime.IScope; | ||
import gama.core.runtime.concurrent.BufferingController.BufferingStrategies; | ||
import gama.core.runtime.exceptions.GamaRuntimeException; | ||
import gama.core.util.GamaListFactory; | ||
import gama.core.util.IList; | ||
|
@@ -124,7 +123,7 @@ public void save(final IScope scope, final IExpression item, final File file, fi | |
sb.append(Strings.LN); | ||
} | ||
if (itemType.id() == IType.MATRIX) { | ||
GamaMatrix<?> matrix = (GamaMatrix) value; | ||
GamaMatrix<?> matrix = (GamaMatrix<?>) value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ Getting worse: Complex Method |
||
matrix.rowByRow(scope, v -> sb.append(toCleanString(v)), () -> sb.append(del), | ||
() -> sb.append(Strings.LN)); | ||
} else { | ||
|
@@ -136,27 +135,9 @@ public void save(final IScope scope, final IExpression item, final File file, fi | |
} | ||
sb.append(Strings.LN); | ||
} | ||
GAMA.askWriteFile(scope, file, sb, saveOptions); | ||
GAMA.getBufferingController().askWriteFile(file.getAbsolutePath(), scope, sb, saveOptions); | ||
} | ||
|
||
/** | ||
* Save. | ||
* | ||
* @param scope | ||
* the scope | ||
* @param fw | ||
* the fw | ||
* @param header | ||
* the header | ||
* @param item | ||
* the item | ||
* @throws GamaRuntimeException | ||
* the gama runtime exception | ||
*/ | ||
private void save(final IScope scope, final File file, final boolean header, final IExpression item, final BufferingStrategies bufferingStrategy) | ||
throws GamaRuntimeException { | ||
|
||
} | ||
Comment on lines
-156
to
-159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ No longer an issue: Excess Number of Function Arguments |
||
|
||
/** | ||
* To clean string. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Name: Bufferingexecutionorder | ||
* Based on the internal empty template. | ||
* Author: baptiste | ||
* Tags: | ||
*/ | ||
|
||
|
||
// This model presents the order of execution of different results you can obtain by using different buffering strategies. | ||
model Bufferingexecutionorder | ||
|
||
global { | ||
|
||
|
||
reflex at_cycle { | ||
write "at cycle " + cycle buffering:"per_cycle"; | ||
save "at cycle " + cycle to:"data.csv" header:false rewrite:false buffering:"per_cycle" format:"csv"; | ||
} | ||
|
||
reflex at_cycle2 { | ||
write "at cycle2 " + cycle + " should appear after 'at cycle "+ cycle+"' as it's asked in that order" buffering:"per_cycle"; | ||
save "at cycle2 " + cycle + " should appear after 'at cycle "+ cycle+"' as it's asked in that order" to:"data.csv" header:false rewrite:false buffering:"per_cycle" format:"csv"; | ||
} | ||
|
||
reflex no_buffering { | ||
write "at cycle " + cycle + " too, should appear before all the other, as it's executed right when the code is reached" buffering:"no_buffering"; | ||
save "at cycle " + cycle + " too, should appear before all the other, as it's executed right when the code is reached" rewrite:false to:"data.csv" header:false buffering:"no_buffering" format:"csv"; | ||
} | ||
|
||
reflex end_of_simulation { | ||
write "Run at cycle " + cycle + " but should only be visible once the simulation is killed." buffering:"per_simulation"; | ||
save "Run at cycle " + cycle + " but should be appended at the end of the file" to:"data.csv" header:false rewrite:false buffering:"per_simulation" format:"csv"; | ||
} | ||
|
||
reflex end_sim when:cycle=4{ | ||
do die; | ||
} | ||
|
||
} | ||
|
||
experiment a type:batch until:cycle=10 autorun:true{ | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Name: Buffering | ||
* Based on the internal empty template. | ||
* Author: baptiste | ||
* Tags: | ||
*/ | ||
|
||
|
||
// This model presents the difference in terms of performance between writing many times directly in a file | ||
// or using a buffering strategy to have all the writing requests grouped into one big at the end of the cycle | ||
// this benchmarking is not using the "benchmark" statement as we also want to include the time it takes for the | ||
// engine to actually write the files at the end of the cycle. | ||
model BufferingPerformances | ||
|
||
|
||
global{ | ||
|
||
int state <- 0; | ||
int nb_rep <- 10000; | ||
float start_time; | ||
|
||
reflex write_duration_buffered when:state=3{ | ||
write "Duration for buffered writing: " + (gama.machine_time - start_time) + "ms"; | ||
do pause; | ||
} | ||
|
||
reflex write_buffered when:state = 2 { | ||
start_time <- gama.machine_time; | ||
loop times:nb_rep{ | ||
save "some text\n" to:"someotherfile.txt" rewrite:false buffering:"per_cycle" format:"txt"; | ||
} | ||
state <- 3; | ||
} | ||
|
||
reflex write_duration_direct when:state = 1 { | ||
write "Duration for direct writing: " + (gama.machine_time - start_time) + "ms"; | ||
state <- 2; | ||
} | ||
|
||
|
||
reflex write_directly when:state=0{ | ||
start_time <- gama.machine_time; | ||
loop times:nb_rep{ | ||
save "some text\n" to:"somefile.txt" rewrite:false buffering:"no_buffering" format:"txt"; | ||
} | ||
state <- 1; | ||
} | ||
|
||
} | ||
|
||
experiment compare; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ Getting worse: Primitive Obsession
The ratio of primitive types in function arguments increases from 30.51% to 39.13%, threshold = 30.0%