Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP Speed
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01534425
Message ID:
01534488
Views:
107
On my computer:
Jose's code completes in 0.868 seconds and in 0.441 seconds respectively.
C# code (below) completes in 0.29 seconds and 0.016 seconds respectively.
using System;
using System.Text;

namespace SpeedTest
{
    using System.Diagnostics;

    public class Program
    {
        public static void Main()
        {
            SpeedTest();

            Console.Write("\n\nAny key...");
            Console.ReadKey();
        }

        private static void SpeedTest()
        {
            const int MaxIndex = 1000000;

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            for (var index = 0; index < MaxIndex; index++)
            {
                var var1 = Math.Log(index) + 
                    Math.Cos(index) + 
                    Math.Sin(index) + 
                    Math.Log(index) + 
                    Math.Exp(index);
            }

            stopwatch.Stop();
            Console.WriteLine("Test 01: {0}", stopwatch.Elapsed);

            // AM  using string type in .NET for this type of test
            // would be unreasonable. StringBuilder Class is used instead.
            var stringBuilder = new StringBuilder();

            stopwatch.Reset();
            stopwatch.Start();

            for (var index = 0; index < MaxIndex; index++)
            {
                stringBuilder.Append("xx");
            }

            string result = stringBuilder.ToString();

            stopwatch.Stop();
            Console.WriteLine("Test 02: {0}", stopwatch.Elapsed);
        }
    }
}
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform