<commit_before>﻿using System;
using System.Data.Common;
using System.Diagnostics;
using System.Net;
using System.Threading;

using Dapper;
using StackExchange.Profiling;

namespace Samples.Console
{
    /// <summary>
    /// simple sample console application.
    /// </summary>
    public static class Program
    {
        private static MiniProfilerOptions Options;

        /// <summary>
        /// application entry point.
        /// </summary>
        /// <param name="args">application command line arguments.</param>
        public static void Main()
        {
            try
            {
                SetupProfiling();
                //Test();
                TestMultiThreaded();
                Report();

                if (Debugger.IsAttached)
                    System.Console.ReadKey();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
        }

        /// <summary>
        /// setup the profiling.
        /// </summary>
        public static void SetupProfiling()
        {
            Options = new MiniProfilerOptions().SetProvider(new SingletonProfilerProvider());
        }

        /// <summary>
        /// test the profiling.
        /// </summary>
        public static void Test()
        {
            var mp = Options.StartProfiler("Test");

            using (mp.Step("Level 1"))
            using (var conn = GetConnection())
            {
                conn.Query<long>("select 1");

                using (mp.Step("Level 2"))
                {
                    conn.Query<long>("select 1");
                }

                using (var wc = new WebClient())
                using (mp.CustomTiming("http", "GET http://google.com"))
                {
                    wc.DownloadString("http://google.com");
                }
            }

            mp.Stop();
        }

        public static void TestMultiThreaded()
        {
            var mp = Options.StartProfiler("Locking");
            Action doWork = () => Thread.Sleep(new Random().Next(1, 50));

            using (mp.Step("outer"))
            {
                System.Threading.Tasks.Parallel.For(0, 5, i =>
                {
                    doWork();

                    using (mp.Step("step " + i))
                    {<commit_msg>Fix for #198<commit_after>﻿using System;
using System.Data.Common;
using System.Diagnostics;
using System.Net;
using System.Threading;

using Dapper;
using StackExchange.Profiling;

namespace Samples.Console
{
    /// <summary>
    /// simple sample console application.
    /// </summary>
    public static class Program
    {
        private static MiniProfilerOptions Options;

        /// <summary>
        /// application entry point.
        /// </summary>
        /// <param name="args">application command line arguments.</param>
        public static void Main()
        {
            try
            {
                SetupProfiling();
                //Test();
                TestMultiThreaded();
                Report();

                if (Debugger.IsAttached)
                    System.Console.ReadKey();
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
        }

        /// <summary>
        /// setup the profiling.
        /// </summary>
        public static void SetupProfiling()
        {
            // We're using DefaultProfilerProvider here (not the Web provider) because we're 
            // not using HttpContext.Current to track MiniPofiler.Current
            // In general, DefaultProfilerProvider() should be the go-to for most new applications.
            Options = new MiniProfilerOptions().SetProvider(new DefaultProfilerProvider());
        }

        /// <summary>
        /// test the profiling.
        /// </summary>
        public static void Test()
        {
            var mp = Options.StartProfiler("Test");

            using (mp.Step("Level 1"))
            using (var conn = GetConnection())
            {
                conn.Query<long>("select 1");

                using (mp.Step("Level 2"))
                {
                    conn.Query<long>("select 1");
                }

                using (var wc = new WebClient())
                using (mp.CustomTiming("http", "GET https://google.com"))
                {
                    wc.DownloadString("https://google.com");
                }
            }

            mp.Stop();
        }

        public static void TestMultiThreaded()
        {
            var mp = Options.StartProfiler("Locking");
            Action doWork = () => Thread.Sleep(new Random().Next(1, 50));

            using (mp.Step("outer"))
            {
                System.Threading.Tasks.Parallel.For(0, 5, i =>
                {
                    doWork();

                    using (mp.Step("step " + i))
                    {
{'fraction_non_alphanumeric': 0.11848245080137959, 'fraction_numerical': 0.00426049908703591, 'mean_word_length': 1.265625, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '650753', 'n_tokens_mistral': 1257, 'n_tokens_neox': 1177, 'n_words': 283}