Exemple #1
0
        private static Dictionary <string, double> RunTest(IDawgFactory factory)
        {
            IEnumerable <KeyValuePair <string, ushort> > pairs = GetWordNumberPairs();

            var metrics = new Dictionary <string, double> ();

            IDawgBuilder dawgBuilder = null;

            var buildTime = Time(() =>
            {
                dawgBuilder = factory.CreateBuilder(pairs);
            });

            metrics.Add("Build Time, ms", buildTime);

            MemoryStream stream = null;

            var saveTime = Time(() =>
            {
                stream = new MemoryStream();
                dawgBuilder.Save(new NonDisposableStream(stream));
            });

            metrics.Add("Save Time, ms", saveTime);
            metrics.Add("File Size, bytes", stream.Position);
            stream.Position = 0;

            IDawg dawg = null;

            var before = GC.GetTotalMemory(true);

            var loadTime = Time(() =>
            {
                dawg = factory.Load(stream);
            });

            var after = GC.GetTotalMemory(true);

            metrics.Add("Load Time, ms", loadTime);
            metrics.Add("RAM, bytes", after - before);

            const int nLookups = 1000000;

            var lookupTime = Time(() =>
            {
                foreach (string word in RandomWords().Take(nLookups))
                {
                    if (dawg [word] == 0)
                    {
                        throw new Exception("dawg [" + word + "] == 0");
                    }
                }
            });

            metrics.Add("Lookups Per Sec", nLookups * 1000.0 / lookupTime);

            var matchPrefixTime = Time(() =>
            {
#pragma warning disable 219
                int x = 0;
#pragma warning restore 219

                foreach (var keyValuePair in RandomWords().SelectMany(w => dawg.MatchPrefix(w.Take(w.Length / 2))).Take(nLookups))
                {
                    x += keyValuePair.Value;
                }
            });

            metrics.Add("Prefix Matches Per Sec", nLookups * 1000.0 / matchPrefixTime);

            return(metrics);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractDawgDecorator{TCKey, TCValue}"/> class.
 /// </summary>
 /// <param name="inner">The inner dawg.</param>
 /// <param name="keyMapper">The object mapper from <see cref="TKey"/> to <see cref="TCKey"/>.</param>
 /// <param name="valueMapper">The object mapper from <see cref="TValue"/> to <see cref="TCValue"/>.</param>
 public MappedDawg(IDawg <TCKey, TCValue> inner, IMappingStrategy <TKey, TCKey> keyMapper,
                   IMappingStrategy <TValue, TCValue> valueMapper) : base(inner)
 {
     this.keyMapper   = keyMapper;
     this.valueMapper = valueMapper;
 }
Exemple #3
0
 internal Dawg(IDawg <TPayload> dawg)
 {
     this.dawg = dawg;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractDawgDecorator{TKey, TValue}"/> class.
 /// </summary>
 /// <param name="inner">The inner dawg.</param>
 public AbstractDawgDecorator(IDawg <TKey, TValue> inner)
 {
     InnerDawg = inner;
 }