Your function is trivial. It's a for
loop with 21 iterations that performs a couple of simple equality tests. It can execute in ~100 cycles. The overhead of OpenMP is many orders of magnitude greater.
Simply put, you cannot expect threads to improve performance here. You need much larger tasks of work for threading to be effective. Single threaded code written in Delphi will be the most efficient way to implement the code in your question.
If removing all the OpenMP doesn't help (you say your code is slow without the OpenMP) then you need to look at your compiler options. Are you compiling with optimisation? If you have a question about performance, you do really need to supply a reproducible test case, with timings.
Your C++ code is rather strange too. It is needlessly complex. It could be written like this:
bool Validate(const char character)
{
const char char_store[] = {
',' , '+' , '-' , '*' , '/', '(' , ')' , '^' , '[' , ']' , '%' ,
'&' , '=' , '<' , '>' , ' ' , '.' , ';' , ':',
char(13) , char(10)};
for(int i = 0; i < 21; i++)
if (char_store[i] == character)
return true;
return false;
}
There's no point whatsoever in putting this code in a DLL, or trying to use a parallel for
. You need to break your program into much bigger units of work for parallelisation to be effective.