示例#1
0
        /// <summary>
        /// just wanted to test the effects of running from the cache instead of calling the api. the effect is dramatic. orders of magnitude better (not unexpected).
        /// </summary>
        /// <param name="passengers"></param>
        /// <param name="client"></param>
        private static void Version2a(int passengers, StarWarsApiClient client)
        {
            var timeStartV2a = new TimeSpan(DateTime.Now.Ticks).Ticks;

            foreach (var starshipPilotCombo in GetStarshipPilotCombosByPassengersVersion2(client, passengers)) //with this call client is old and the results will be from cache
            {
                Console.WriteLine(starshipPilotCombo);
            }

            Console.WriteLine(new TimeSpan(DateTime.Now.Ticks).Ticks - timeStartV2a);
        }
示例#2
0
        /// <summary>
        /// this version calls version 2 and will load all pilots from a starship at the same time (this should be faster...and usually is, however, a lot of the results have
        /// very few pilots and there is overhead with the tasks. if the data had more pilots per starship then this version should really pull ahead.
        /// </summary>
        /// <param name="passengers"></param>
        /// <param name="client"></param>
        private static void Version2(int passengers, StarWarsApiClient client)
        {
            var timeStartV2 = new TimeSpan(DateTime.Now.Ticks).Ticks;

            foreach (var starshipPilotCombo in GetStarshipPilotCombosByPassengersVersion2(client, passengers, (starship, person) => $"Version2 - {starship.Name} - {person.Name}")) //with this call client is new and the results will be real
            {
                Console.WriteLine(starshipPilotCombo);
            }

            Console.WriteLine(new TimeSpan(DateTime.Now.Ticks).Ticks - timeStartV2);
        }
示例#3
0
        static void Main(string[] args)
        {
            // Story: The intergalactic logistics team needs a program that can generate a list of Starship and Pilot combinations that can transport a given number of passengers.
            // For example, if I have 3000 passengers I need to know which starships can fit 3000 passengers and which pilots can pilot them.
            // Write a program or function that accepts a number passengers as input and outputs a string "{Starship} - {Pilot}" for each suitable starship and pilot combination.


            /* Tried a few different ways to get the data. I originally thought that \starships would get me all of them and then I could filter and then load all of the pilots
             * at the same time...but because of the paging when calling \starships I only get 10 of them at a time. So I handle the paging in the apiclient and this means that
             * the best I can do is load a page of starships, then filter to starships that meet my criteria and then asynchronous load all of the pilots for that starship
             */

            var passengers = 1;

            // **** Version 0 ****
            // this version calls version 1 but then I use links foreach to write the results to the console. however, to do this I have to convert the IEnumerable to a List this
            // will block and wait for all of the results (kill the benefits of yield return) before writing anything.

            //Version0(passengers); //to see this just uncomment
            // **** Version 0 ****


            // **** Version 1 ****
            // this version calls version 1 and will load 1 pilot at a time

            Version1(passengers);
            // **** Version 1 ****


            // **** Version 2 ****
            //this version calls version 2 and will load all pilots from a starship at the same time (this should be faster...and usually is, however, a lot of the results have
            //very few pilots and there is overhead with the tasks. if the data had more pilots per starship then this version should really pull ahead.

            var client = new StarWarsApiClient();

            Version2(passengers, client);
            // **** Version 2 ****


            // **** Version 2a ****
            //just wanted to test the effects of running from the cache instead of calling the api. the effect is dramatic. orders of magnitude better (not unexpected).

            //Version2a(passengers, client); //to see this just uncomment
            // **** Version 2a ****

            Console.ReadKey();
        }