These are chat archives for OrchardCMS/Orchard

23rd
Nov 2016
vlatkost
@vlatkost
Nov 23 2016 08:54
@roballred I actually never use the archive. I know almost every blog has it, but to me it kinda seems unnecessary as most people come from link outside the site or search the site for a specific post. However I'll have a look tonight and see if I can help you out in any way. It would also help to know what your desired result is and how much that defers from the usual archive section (year/month/date) of blogs
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 09:28
hi.
Does anyone know how to consistently measure exection time of some method? I usually used System.Diagnostic.Stopwatch, but it's looking weird here.
I have two variants of a method, and I would like to check which one is faster. So I am calling them one after the other and doing:
Stopwatch sw = Stopwatch.StartNew();
MethodVariant1();
sw.Stop();
sw.Restart(); //get sw.ElapsedTicks before calling this
MethodVariant2();
sw.Stop();
DoStuff; //get sw.ElapsedTicks
the weird thing is that no matter the order of execution of the method variants, the one being executed second is about one order of magnitude faster
Could there be some weird optimization happening behind my back at runtime?
Carl Woodhouse
@carlwoodhouse
Nov 23 2016 09:58
@roballred you could probably just create a projection query then show that in a widget ...
ifle
@ifle
Nov 23 2016 11:15
@MatteoPiovanelli-Laser
Something like this
public static void Measure(string name, Func<long> callback)
{
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();

    var mem = GC.GetTotalMemory(true);
    var gc00 = GC.CollectionCount(0);
    var gc01 = GC.CollectionCount(1);
    var gc02 = GC.CollectionCount(2);

    var sw = Stopwatch.StartNew();
    var result = callback();
    sw.Stop();

    var mem2 = GC.GetTotalMemory(false);
    GC.WaitForFullGCComplete(100);
    var gc10 = GC.CollectionCount(0);
    var gc11 = GC.CollectionCount(1);
    var gc12 = GC.CollectionCount(2);

    var memDelta = (mem2 - mem) / 1024.0;
    var gcDelta0 = gc10 - gc00;
    var gcDelta1 = gc11 - gc01;
    var gcDelta2 = gc12 - gc02;

    Console.WriteLine(
        "{0,14}: {1,5}ms, ips: {2,22:N} | Mem: {3,10:N2} kb, GC 0/1/2: {4}/{5}/{6} => {7,6}",
        name, sw.ElapsedMilliseconds, result / sw.Elapsed.TotalSeconds, memDelta, gcDelta0, gcDelta1, gcDelta2, result);
}
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 11:23

@ifle so, if I only needed time and not memory, would I just have to add

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

before both my Stopwatch.StartNew() and sw.Restart()?

ifle
@ifle
Nov 23 2016 11:28
@ifle Yes, for time it's enough, but do you understand that there are a lot of things why your measuring may be not deterministic: like cold start, JIT and etc'
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 11:30
@ifle Yes, I understand. I just need a rough idea to see whether either version of the method is significantly and/or consistently faster than the other. I don't need to be precise about how much faster one is. I'll run the thing a few dozen times to have an idea and see.
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 13:36
@ifle I tried as we discussed, but I still get that whatever method I run first is slower. I guess the JIT or something is pulling one over me
Hazzamanic
@Hazzamanic
Nov 23 2016 14:20
anyone written any unit tests for Orchard? I generated them using codegen moduletests but my tests I write are not appearing in the Test Explorer
all the other Orchard tests are there
I've restarted vs, run as admin, rebuilt a million times etc.
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 14:22
I have not done it myself. I remember however a thread about tests on github. Not sure if it is what you are looking for, but give me a minute to dig it out
OrchardCMS/OrchardDoc#304
I hope that helps
Hazzamanic
@Hazzamanic
Nov 23 2016 14:45
it's weird, the Orchard tests are all there, but mine are not
Xceno
@Xceno
Nov 23 2016 14:59
@Hazzamanic I've written tests
pretty much the only thing I've done without the codegen though
Hazzamanic
@Hazzamanic
Nov 23 2016 15:00
so you just put unit tests in your module?
Xceno
@Xceno
Nov 23 2016 15:01
pretty much yeah I have another project inside of my module so it stays together.
So my structure looks like Modules\MyModule\MyModule.Tests
MyModule.Tests is a class library
therein I have an abstract class inheriting from DatabaseEnabledTestsBase
which does a bunch of setups / wiring like the other test projects.
All my test classes inherit from this abstract class and get marked with the usual [TextFixture]
Hazzamanic
@Hazzamanic
Nov 23 2016 15:04
okay, and where is the .Tests project in your solution?
Xceno
@Xceno
Nov 23 2016 15:04
I've included it in the Tests folder beside the other projects
Hazzamanic
@Hazzamanic
Nov 23 2016 15:07
man
so adding a test to my actual module, and it appears in the test explorer
but not the tests in my test project
blob
now I'm just being stubborn wanting my test project to work haha
Xceno
@Xceno
Nov 23 2016 15:09
hahah :D yeah i know that feeling today
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 15:10
might be worth checking that your test project has the same version of NUnit
Xceno
@Xceno
Nov 23 2016 15:10
but your Tests project is included in the "Modules" folder in the solution?
true
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 15:10
maybe you are using a more recent version than Orchard's
Xceno
@Xceno
Nov 23 2016 15:11
heres my packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Autofac" version="3.5.2" targetFramework="net452" />
  <package id="FluentNHibernate" version="2.0.3.0" targetFramework="net452" />
  <package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net452" />
  <package id="Moq" version="4.0.10827" targetFramework="net452" />
  <package id="NHibernate" version="4.0.1.4000" targetFramework="net452" />
  <package id="NodaTime" version="1.3.2" targetFramework="net452" />
  <package id="NUnit" version="2.5.10.11092" targetFramework="net452" />
</packages>
working on 1.10.x
Hazzamanic
@Hazzamanic
Nov 23 2016 15:12
versions are the same, I've just been dragging that project all over cos I have no idea what to do with it haha
Xceno
@Xceno
Nov 23 2016 15:15
hm maybe something other than that is messed up. I'd try creating a new tests project without the orchard cmdline tools
Hazzamanic
@Hazzamanic
Nov 23 2016 15:21
yeah course that worked, thanks @Xceno @MatteoPiovanelli-Laser for the help
Xceno
@Xceno
Nov 23 2016 15:22
cool! np
Hazzamanic
@Hazzamanic
Nov 23 2016 15:22
just tried the codegen command again, still didn't work
could be something wrong with the templates
now can go back to writing the actual tests :( kinda wish it was still broken now haha
Xceno
@Xceno
Nov 23 2016 15:26
if you want to slack off you can debug the codegen command :D :P
Hazzamanic
@Hazzamanic
Nov 23 2016 15:27
true
Matteo Piovanelli
@MatteoPiovanelli-Laser
Nov 23 2016 21:44
@sebastienros I am going to log off now. If you find you can spare some more time to give more ideas on the cloning I would read it tomorrow. If nothing else, I will try to move the fallback into the abstract classes and see if I can find a way to work around it overwriting the other cloning behaviour