Remove Visual Studio Navigation Bar

by rsutton 31. July 2009 06:12

It has been my quest recently to maximize my Visual Studio real estate.  Today I just realized that the drop down list that always appears at the top of my source files (something I never use) is called the navigation bar.  With this info I was able to remove one more space waster that I never use.

 

Before

image

Turn it off

image

After

image

Tags:

Speed Test Reflection vs IronPython

by rsutton 30. July 2009 08:10

I was getting ready to write some code that will apply rules to an object using reflection, when I realized I could do the same thing using IronPython.  My only concern was the performance implications, because what I was doing needed to be fast.

 

Here are the results of basically setting properties on an object using both python and reflection.

image

Here is the code.  Nothing fancy.  I didn’t notice that there is a hit with the initial run, but after that IronPython is much faster.  If you look at the code you will notice that the time does not include setting up the engine, scope, etc.  You can play with those yourself, because here is the code.

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Running 1000");

            RunIteration(1000);

 

            Console.WriteLine("Running 10000");

            RunIteration(10000);

 

            Console.WriteLine("Running 100000");

            RunIteration(100000);

 

            Console.WriteLine("Running 1000000");

            RunIteration(1000000);

 

            Console.WriteLine("Running 10000000");

            RunIteration(10000000);

 

            Console.WriteLine("Running 10000000");

            RunIteration2(10000000);

 

            Console.ReadLine();

        }

 

        static void RunIteration(int iterations)

        {

            Console.WriteLine("Reflection Iteration.");

            TestReflection(iterations);

            Console.WriteLine("Python Iteration.");

            TestPython(iterations);

            Console.WriteLine("Testing Complete.");

            Console.WriteLine();

        }

 

        static void RunIteration2(int iterations)

        {

            Console.WriteLine("Reflection Iteration 2.");

            TestReflection(iterations);

            Console.WriteLine("Python Iteration 2.");

            TestPython2(iterations);

            Console.WriteLine("Testing Complete.");

            Console.WriteLine();

        }

 

        static void TestReflection(int iterations)

        {

            var test = new TestClass();

            var type = test.GetType();

 

            var st = new Stopwatch();

            st.Start();

 

            for (var i = 0; i < iterations; i++)

            {

                type.GetProperty("Id").SetValue(test, 1, null);

                type.GetProperty("Name").SetValue(test, "New Name", null);

            }

 

            st.Stop();

 

            Console.WriteLine("Time {0} ms", st.ElapsedMilliseconds);

        }

 

        static void TestPython(int iterations)

        {

            var engine = Python.CreateEngine();

            var sourceengine.CreateScriptSourceFromFile("test.py");

            var scope = engine.CreateScope();

 

            var test = new TestClass();

 

            source.Engine.SetVariable(scope, "test", test);

            source.Engine.SetVariable(scope, "iterations", iterations);

 

            var st = new Stopwatch();

            st.Start();

            source.Execute(scope);

            st.Stop();

 

            Console.WriteLine("Time {0} ms", st.ElapsedMilliseconds);

        }

 

        static void TestPython2(int iterations)

        {

            var engine = Python.CreateEngine();

            var sourceengine.CreateScriptSourceFromFile("test2.py");

            var scope = engine.CreateScope();

 

            var test = new TestClass2();

 

            source.Engine.SetVariable(scope, "test", test);

            source.Engine.SetVariable(scope, "iterations", iterations);

 

            var st = new Stopwatch();

            st.Start();

            source.Execute(scope);

            st.Stop();

 

            Console.WriteLine("Time {0} ms", st.ElapsedMilliseconds);

        }

    }

 

    public class TestClass

    {

        public int Id { get; set; }

        public string Name { get; set; }

    }

 

    public class TestClass2

    {

        public int Id2 { get; set; }

        public string Name2 { get; set; }

    }

test.py

for i in range(0,iterations):

    test.Id = 1

    test.Name = 'New Name'

test2.py

for i in range(0,iterations):

    test.Id2 = 1

    test.Name2 = 'New Name'

Tags:

Development

Simple IronPython and C# Interaction Example

by rsutton 29. July 2009 01:47

I have yet to find a simple example of executing an IronPython script from C#, so here is mine.  Note that the Project I created is called ByFeatureApp and the WebScrapper class is public.  I also show setting a variable (the) in C# and then the python script prints the value.

 

C# Code

namespace ByFeatureApp

{

    class Program

    {

        static void Main(string[] args)

        {

            var the = "hello I'm the the string";

 

            var engine = Python.CreateEngine();

            var source = engine.CreateScriptSourceFromFile("Scripts\\test.py");

            var scope = engine.CreateScope();

            source.Engine.SetVariable(scope, "the", the);

            source.Execute(scope);

 

            Console.ReadLine();

        }

    }

 

    public class WebScraper

    {

        public void LoadUrl(string url)

        {

            Html = new WebClient().DownloadString(url);

        }

 

        public string Html { get; set; }

    }

}

 

IronPython Script

import clr

clr.AddReference('ByFeatureApp')

from ByFeatureApp import *

 

print the

 

ws = WebScraper()

ws.LoadUrl('http://www.barchart.com')

 

istart = ws.Html.find('<tr><td><a href="http://quote.barchart.com/quote.asp?sym=GCQ9">Gold</a>')

iend = ws.Html.find('</tr>', istart)

 

print ws.Html[istart:iend+5]

 

Anyway I hope this is useful.

Tags:

Development

Powered by BlogEngine.NET 1.4.5.0
Theme by Extensive SEO

Profile

Member of the Church of Jesus Christ of Latter-Day Saints, Developer and IT Professional