Identify the function(s) which are causing performance issues.
The internal implementation of GetThreadNum calls Convert.ToInt32 on the thread's name each time it's called. String->int conversion is notably slow, so this can be drastically improved by caching the results on the first call into a thread-local variable.
Provide example code.
public static int GetThreadNum()
{
if (!InParallel())
{
throw new NotInParallelRegionException("Cannot get current thread number outside of a parallel region.");
}
return Convert.ToInt32(Thread.CurrentThread.Name);
}
This is the implementation of GetThreadNum.
Describe the performance expected vs. performance observed.
TODO: fill in later
Desktop (please complete the following information):
Identify the function(s) which are causing performance issues.
The internal implementation of
GetThreadNum
callsConvert.ToInt32
on the thread's name each time it's called. String->int conversion is notably slow, so this can be drastically improved by caching the results on the first call into a thread-local variable.Provide example code.
This is the implementation of
GetThreadNum
.Describe the performance expected vs. performance observed.
TODO: fill in later
Desktop (please complete the following information):
Additional context?
Self-assigning this issue for now.