Skip to content

Addition of concatenate operator#292

Merged
lesquoyb merged 2 commits into
2024-06from
Addition-of-concatenate
Aug 25, 2024
Merged

Addition of concatenate operator#292
lesquoyb merged 2 commits into
2024-06from
Addition-of-concatenate

Conversation

@AlexisDrogoul

Copy link
Copy Markdown
Member

Takes a list of strings in parameter and produces the string resulting from their concatenation

Takes a list of strings in parameter and produces the string resulting from their concatenation

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

Change in average Code Health of affected files: +0.00 (7.11 -> 7.11)

  • Improving Code Health: 2 findings(s) ✅

View detailed results in CodeScene

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

Change in average Code Health of affected files: +0.00 (7.11 -> 7.11)

  • Improving Code Health: 2 findings(s) ✅

View detailed results in CodeScene

package gama.gaml.operators;

import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: Primitive Obsession
The ratio of primitive types in function arguments decreases from 85.19% to 79.66%, threshold = 30.0%

package gama.gaml.operators;

import java.nio.charset.StandardCharsets;
import java.util.StringJoiner;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: String Heavy Function Arguments
The ratio of strings in function arguments decreases from 72.22% to 67.80%, threshold = 39.0%

@lesquoyb

Copy link
Copy Markdown
Contributor

It is indeed way more efficient to save big files as demonstrated by this example model:

model CONCAT

global{
	
	int nb_concat <- 10000;
	
	float seed <- 3.14;
	string f <- "file.txt";
	
	init {
		save "" to:f rewrite:true;	
	}
	
	reflex eval {		
		do save_directly;
		do optimized_save_directly;
		do concat_first;
		do concat_ope;
		do save_list;
	}
	
	action concat_first{
		benchmark message:"\nconcat string" repeat:10 {
			string s <- "";
			loop i from:0 to:nb_concat{
				s <- s + "" + rnd(0, 9);
			}
			save s to:f format:"txt";
		}
	}
	
	action save_directly {
		benchmark message:"\nsave directly" repeat:10 {
			loop i from:0 to:nb_concat{
				save "" + rnd(0, 9) to:f rewrite:false format:"txt";
			}
		}
	}
	
	action optimized_save_directly {
		benchmark message:"\noptimized save directly" repeat:10 {
			loop i from:0 to:nb_concat{
				save "" + rnd(0, 9) to:f rewrite:false format:"txt" buffering:"per_simulation";
			}
		}
	}
	
	action save_list{
		benchmark message:"\nsave list" repeat:10 {
			list<string> l;
			loop i from:0 to:nb_concat{
				l <+  "" + rnd(0, 9);
			}
			loop i over:l{
				save i to:f format:"txt" buffering:"per_simulation";				
			}
		}
	}
	
	action concat_ope {
		benchmark message:"\nconcatenate operator" repeat:10 {
			list<string> l;
			loop i from:0 to:nb_concat{
				l <+  "" + rnd(0, 9);
			}
			save concatenate(l) to:f format:"txt";
		}
	}
}

experiment b;

@lesquoyb
lesquoyb merged commit e38a76b into 2024-06 Aug 25, 2024
@AlexisDrogoul
AlexisDrogoul deleted the Addition-of-concatenate branch March 19, 2025 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants