이 문제를 설명하기 위해 Microsoft Scripting Runtime 참조 및 아래 코드를 사용하여 C# 프로젝트를 컴파일하십시오. 결과 실행 파일의 단일 인스턴스를 실행하십시오. 내 12 코어 머신에서 읽기 루프는 일관되게 약 180ms가 걸립니다. 실행 파일의 다른 인스턴스를 시작하면 추가 실행 파일 당 약 100ms 정도 속도가 느려집니다.Scripting.Dictionary 성능이 여러 프로세스에서 발생합니다.
아이디어가 있습니까? 다른 사전 구현으로 전환하는 것 이외의 다른 솔루션이 있습니까?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Stopwatch stp = new System.Diagnostics.Stopwatch();
var dict = (Scripting.IDictionary)(new Scripting.Dictionary());
stp.Start();
for (int i = 1; i < 1000; ++i)
{
Object s = i.ToString();
dict.Add(ref s, ref s);
}
Console.WriteLine("After Add {0}", stp.ElapsedMilliseconds);
object q = null;
for (int j = 0; j < 1000; ++j)
{
long old = stp.ElapsedMilliseconds;
for (int i = 1; i < 10000; ++i)
{
q = null;
object s = i.ToString() as object;
q = dict.get_Item(ref s);
}
long newval = stp.ElapsedMilliseconds;
Console.WriteLine("After Retrieve {0}", newval - old);
}
}
}
}
타이밍 코드가있는 동안 콘솔을 가로 질러 1000 줄의 텍스트를 스크롤하는 것은 정말 나쁜 생각입니다. –
나는 1997 년에'ScriptingDictionary'를 썼습니다.나는 당신의 문제의 원인이 무엇인지 모르지만, 알아내는 것이 궁금 할 것입니다. 그것이 무엇이든, 나는 결코 고칠 수 없을 것이라고 확신 할 수 있습니다. –