Commit Graph

7 Commits (master)

Author SHA1 Message Date
Fulgen301 73b52a15ce Remove StringToInteger function 2017-06-14 21:11:39 +02:00
Maikel de Vries 2b88e77254 adapt System.ocg headers to style guidelines and small clean ups 2017-06-02 17:15:08 +02:00
Maikel de Vries 823b13d764 add simple string to integer conversion function
Just a basic one in C4Script for now.
2016-09-18 11:30:35 +02:00
Lukas Werling db12ed7c99 Remove FindSubstring as it's really really slow
Use RegexSearch() instead, which is 100 times faster for large strings
(see benchmark results below).

Example benchmark:

    global func TestFindSubstring(int iterations)
    {
    	var result;
    	for (var i = 0; i < iterations; i++)
    	{
    		result = FindSubstring(hamlet, "and");
    	}
    	return result;
    }

    global func TestRegexSearch(int iterations)
    {
    	var result;
    	for (var i = 0; i < iterations; i++)
    	{
    		result = RegexSearch(hamlet, "and");
    	}
    	return result;
    }

    global func RunBenchmark(int iterations)
    {
    	StartScriptProfiler();
    	Log("FindSubstring: %d iterations", iterations);
    	var substr = TestFindSubstring(iterations);
    	Log("RegexSearch: %d iterations", iterations);
    	var regex = TestRegexSearch(iterations);
    	StopScriptProfiler();

    	if (!DeepEqual(regex, substr))
    		Log("Results differ: %v vs %v", substr, regex);
    }

Results:

    FindSubstring: 100 iterations
    RegexSearch: 100 iterations
    Profiler statistics:
    ==============================
    48903ms      Global.FindSubstring
    48903ms      Global.TestFindSubstring
    47979ms      Global.TakeString
    00504ms      Global.TestRegexSearch
    00016ms      Global.PushBack
    ==============================
2016-09-17 20:08:43 +02:00
Maikel de Vries 4b54b86d30 add function to find substrings 2016-09-16 17:25:22 +02:00
Maikel de Vries 17f98bd235 add helper functions chars 2016-09-06 17:06:05 +02:00
Maikel de Vries 3580605ba2 fix ToEmString and introduce ToPercentString for GUIs
The previous implementation could not handle value = -1 and factor = 10 or value = 1 and factor = 100, nor factors which are not powers of ten.
2015-06-05 12:06:02 +02:00