How to measure memory and CPU NHibernate is using?

Skip to first unread message

Rafael Lillo

Jun 12, 2019, 4:41:30 AM6/12/19
to nhibernate-development

I create ObjectPool to share StringBuilder in NHibernate and I would like to measure how much memory and CPU is using before and after my change, How to do this?

I made those change based on these article:

I didn't open PR yet

Oskar Berggren

Jun 12, 2019, 6:38:56 AM6/12/19
Well, it would be interesting to see if that improves performance.

As for your question, that's not really a question specific to NHibernate. It seems the question is more related to general profiling. Write some unit test or system test that perform a set amount of work and measure it - run time or using profiling tools. I expect there to be loads of stuff on this on the web so I won't try to repeat it here. Unless you have a more specific question on the subject?

The first link you posted also has this very important comment:
All in all there are some really nice tricks and examples of high-performance code to be found in the Roslyn code base. But the main lesson is that you should never be applying these for the sake of it or because they look clever. They should only be used in conjunction with proper performance testing that identifies the parts of your code that cause it to run slower than your performance goals.

It can of course be a fun exercise to refactor some code, but what you can consider is to try to figure out a test and profile CPU consumption _first_ to find hotspots or identify if something is an actual hotspot before changing the code. Then that same test should reveal if the change improved matters.

Another matter is of course if the performance should be measured on some real-world scenario, or a scenario specifically designed to expose some suspected hotspot. Both has it's uses, but if the latter one becomes very contrived it doesn't really matter in the real world and may potentially actually be harmful.



You received this message because you are subscribed to the Google Groups "nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit
Reply all
Reply to author
0 new messages