Nexport Solutions

  • Home
  • Partners
  • About Us
    • Meet the Team
  • Contact
  • Support
    • Accessibility
  • Blog
    • Release Announcements
    • Press Releases
    • Build Status
  • Careers
  • Request a Demo
  • Home
  • Partners
  • About Us
    • Meet the Team
  • Contact
  • Support
    • Accessibility
  • Blog
    • Release Announcements
    • Press Releases
    • Build Status
  • Careers
  • Request a Demo

RazorEngine versus Nvelocity Performance 

12/3/2014

1 Comment

 
We use the Nvelocity templating engine to produce much of our user-templated text. This includes CMS text, assignment descriptions, and many other places.

I've been considering a move to the RazorEngine. No descision has been made yet but I wanted to publish our test results.

Method

I looked at several parsing methods.


RazorEngine Raw Parse 
This uses the build-in parse helper method in razor engine with no template name. 
Razor.Parse(template, model);


Razor Compiled parse 
This uses the same method but adds the template name. By adding the template name RazorEngine will use the compiled version on subsequent calls.  
Razor.Parse(template, model, "test");

NVelocity Parse 
This method uses a single NVelocity Parsing Engine Context to perform its work.


NVelocity Singleton

This method uses the Velocity.Init() and Velocity.Evaluate() methods. This allows NVelocity to track it's own singleton pool of parsers.

The Templates

Razor Template
@Model.Name, the narrator, announces his intent to ship aboard a whaling vessel. He has made several voyages as a sailor but none as a whaler. He travels to New Bedford, Massachusetts, where he stays in a whalers’ inn. Since the inn is rather full, he has to share a bed with a harpooner from the South Pacific named Queequeg. At first repulsed by Queequeg’s strange habits and shocking appearance (Queequeg is covered with tattoos), Ishmael eventually comes to appreciate the man’s generosity and kind spirit, and the two decide to seek work on a whaling vessel together. They take a ferry to Nantucket, the traditional capital of the whaling industry. There they secure berths on the Pequod, a savage-looking ship adorned with the bones and teeth of sperm whales. Peleg and Bildad, the Pequod’s Quaker owners, drive a hard bargain in terms of salary. They also mention the ship’s mysterious captain, Ahab, who is still recovering from losing his leg in an encounter with a sperm whale on his last voyage. The Pequod leaves Nantucket on a cold Christmas Day with a crew made up of men from many different countries and races. Soon the ship is in warmer waters, and Ahab makes his first appearance on deck, balancing gingerly on his false leg, which is made from a sperm whale’s jaw. He announces his desire to pursue and kill Moby Dick, the legendary great white whale who took his leg, because he sees this whale as the embodiment of evil. Ahab nails a gold doubloon to the mast and declares that it will be the prize for the first man to sight the whale. As the Pequod sails toward the southern tip of Africa, whales are sighted and unsuccessfully hunted. During the hunt, a group of men, none of whom anyone on the ship’s crew has seen before on the voyage, emerges from the hold. The men’s leader is an exotic-looking man named Fedallah. These men constitute Ahab’s private harpoon crew, smuggled aboard in defiance of Bildad and Peleg. Ahab hopes that their skills and Fedallah’s prophetic abilities will help him in his hunt for Moby Dick. The Pequod rounds Africa  
@if (Model == null){
    <span>Null Here</span> 
} and enters the Indian Ocean. A few whales are successfully caught and processed for their oil. From time to time, the ship encounters other whaling vessels. Ahab always demands information about Moby Dick from their captains. One of the ships, the Jeroboam, carries Gabriel, a crazed prophet who predicts doom for anyone who threatens Moby Dick. His predictions seem to carry some weight, as those aboard his ship who have hunted the whale have met disaster. While trying to drain the oil from the head of a captured sperm whale, Tashtego, one of the Pequod’s harpooners, falls into the whale’s voluminous head, which then rips free of the ship and begins to sink. Queequeg saves Tashtego by diving into the ocean and cutting into the slowly sinking head. During another whale hunt, Pip, the Pequod’s black cabin boy,

VTL Template

$Model.Name, the narrator, announces his intent to ship aboard a whaling vessel. He has made several voyages as a sailor but none as a whaler. He travels to New Bedford, Massachusetts, where he stays in a whalers’ inn. Since the inn is rather full, he has to share a bed with a harpooner from the South Pacific named Queequeg. At first repulsed by Queequeg’s strange habits and shocking appearance (Queequeg is covered with tattoos), Ishmael eventually comes to appreciate the man’s generosity and kind spirit, and the two decide to seek work on a whaling vessel together. They take a ferry to Nantucket, the traditional capital of the whaling industry. There they secure berths on the Pequod, a savage-looking ship adorned with the bones and teeth of sperm whales. Peleg and Bildad, the Pequod’s Quaker owners, drive a hard bargain in terms of salary. They also mention the ship’s mysterious captain, Ahab, who is still recovering from losing his leg in an encounter with a sperm whale on his last voyage. The Pequod leaves Nantucket on a cold Christmas Day with a crew made up of men from many different countries and races. Soon the ship is in warmer waters, and Ahab makes his first appearance on deck, balancing gingerly on his false leg, which is made from a sperm whale’s jaw. He announces his desire to pursue and kill Moby Dick, the legendary great white whale who took his leg, because he sees this whale as the embodiment of evil. Ahab nails a gold doubloon to the mast and declares that it will be the prize for the first man to sight the whale. As the Pequod sails toward the southern tip of Africa, whales are sighted and unsuccessfully hunted. During the hunt, a group of men, none of whom anyone on the ship’s crew has seen before on the voyage, emerges from the hold. The men’s leader is an exotic-looking man named Fedallah. These men constitute Ahab’s private harpoon crew, smuggled aboard in defiance of Bildad and Peleg. Ahab hopes that their skills and Fedallah’s prophetic abilities will help him in his hunt for Moby Dick. The Pequod rounds Africa  
#if ($Model){
    <span>Null Here</span> 
#end and enters the Indian Ocean. A few whales are successfully caught and processed for their oil. From time to time, the ship encounters other whaling vessels. Ahab always demands information about Moby Dick from their captains. One of the ships, the Jeroboam, carries Gabriel, a crazed prophet who predicts doom for anyone who threatens Moby Dick. His predictions seem to carry some weight, as those aboard his ship who have hunted the whale have met disaster. While trying to drain the oil from the head of a captured sperm whale, Tashtego, one of the Pequod’s harpooners, falls into the whale’s voluminous head, which then rips free of the ship and begins to sink. Queequeg saves Tashtego by diving into the ocean and cutting into the slowly sinking head. During another whale hunt, Pip, the Pequod’s black cabin boy,

Results

All results are in TICKS. 10,000 TICKS = 1 MILLISECOND.
----------------
Begining Test Run 1
----------------
Razor Raw Parse took 55855585
Razor Compiled parse 1 took 24572457
Razor Compiled Parse 2 took 0
NVelocity Parse took 6130613
NVelocity Parse 2 took 10001
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 50005
NVelocity Singleton Parse 2 took 10001


----------------
Begining Test Run 2
----------------
Razor Raw Parse took 5300530
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 0
NVelocity Parse 2 took 0
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 0
NVelocity Singleton Parse 2 took 10001


----------------
Begining Test Run 3
----------------
Razor Raw Parse took 5560556
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 10001
NVelocity Parse took 10001
NVelocity Parse 2 took 0
NVelocity Parse 3 template changed took 0
NVelocity Singleton Parse 1 took 0
NVelocity Singleton Parse 2 took 10001


----------------
Begining Test Run 4
----------------
Razor Raw Parse took 5380538
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 0
NVelocity Parse 2 took 0
NVelocity Parse 3 template changed took 0
NVelocity Singleton Parse 1 took 10001
NVelocity Singleton Parse 2 took 10001


----------------
Begining Test Run 5
----------------
Razor Raw Parse took 5270527
Razor Compiled parse 1 took 10001
Razor Compiled Parse 2 took 0
NVelocity Parse took 0
NVelocity Parse 2 took 0
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 10001
NVelocity Singleton Parse 2 took 10001


----------------
Begining Test Run 6
----------------
Razor Raw Parse took 5410541
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 10001
NVelocity Parse 2 took 10001
NVelocity Parse 3 template changed took 0
NVelocity Singleton Parse 1 took 0
NVelocity Singleton Parse 2 took 0


----------------
Begining Test Run 7
----------------
Razor Raw Parse took 5380538
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 10001
NVelocity Parse 2 took 10001
NVelocity Parse 3 template changed took 0
NVelocity Singleton Parse 1 took 0
NVelocity Singleton Parse 2 took 0


----------------
Begining Test Run 8
----------------
Razor Raw Parse took 5580558
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 10001
NVelocity Parse 2 took 10001
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 0
NVelocity Singleton Parse 2 took 0


----------------
Begining Test Run 9
----------------
Razor Raw Parse took 5470547
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 0
NVelocity Parse 2 took 0
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 10001
NVelocity Singleton Parse 2 took 0


----------------
Begining Test Run 10
----------------
Razor Raw Parse took 5360536
Razor Compiled parse 1 took 0
Razor Compiled Parse 2 took 0
NVelocity Parse took 40004
NVelocity Parse 2 took 10001
NVelocity Parse 3 template changed took 10001
NVelocity Singleton Parse 1 took 10001
NVelocity Singleton Parse 2 took 0

1 Comment

NexPort Campus Moves to Fluent Validation

11/14/2013

0 Comments

 
Starting with NexPort Campus v5.1 NexPort will support both Castle Validation and Fluent Validation. Castle Validation will be completely phased out by v6.0 and replaced by Fluent Validation.
Fluent Validations are created in a similar manner to an Nhibernate Mapping. Here is an example of a model entity with its mapping and validator.
          
using FluentValidation;
using FluentValidation.Attributes;
[Validator(typeof(ValidationTestEntityValidator))]
public class ValidationTestEntity : ModelBase
{
public virtual String Phone { get; set; }
public virtual string CreditCard { get; set; }
public virtual int NumGreaterThan7 { get; set; }
public virtual int NumBetween2And27 { get; set; }
}

public class ValidationTestEntityMap : FluentNHibernate.Mapping.ClassMap&lt;validationtestentity&gt;
{
public const string TableName = "ValidationTestEntity";
public ValidationTestEntityMap()
{
Table(TableName);
Id(x =&gt; x.Id)
.GeneratedBy.Assigned()
.UnsavedValue(new Guid("DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF"));
Map(e =&gt; e.Phone);
Map(e =&gt; e.CreditCard);
Map(e =&gt; e.NumGreaterThan7);
Map(e =&gt; e.NumBetween2And27);

}
}
public class ValidationTestEntityValidator : AbstractValidator&lt;validationtestentity&gt;
{
public ValidationTestEntityValidator()
{
RuleFor(e =&gt; e.CreditCard).CreditCard().NotEmpty();
RuleFor(e =&gt; e.NumGreaterThan7).GreaterThan(7);
RuleFor(e =&gt; e.NumBetween2And27).GreaterThan(2).LessThan(27);
}
}
Simple entity validation can be performed anytime by instantiating the validator directly and testing the result:
                 var validator = new ValidationTestEntityValidator();                 var result = validator.Validate(entity); 
Validation can also be performed anytime by using the Validation Factory:
                var factory = new FluentValidatorFactory();                 var validator = factory.CreateInstance(entity.GetType());                 validator.Validate(entity); 
The ValidatorAttribute is applied to the model entity to let the ValidatorFactory know which validator to use.
          [Validator(typeof(ValidationTestEntityValidator))]     public class ValidationTestEntity : ModelBase     { 
When saving or updating an entity to an Nhibernate session there is no need to validate it first. A validation check is performed in the ModelBaseEventListener for all updates and inserts. If the entity fails to validate then a ValidationExcpetion will be thrown. Until v6.0 the ModelBaseEventListener will validate against both the Fluent and Castle validation frameworks.
     using (var session = NHibernateHelper.OpenSession())             {                 session.BeginTransaction(IsolationLevel.ReadUncommitted);                 var testObj = session.Load<ValidationTestEntity>(id);                 // THIS IS NOT A VALID CREDIT CARD NUMBER                 testObj.CreditCard = "123667";                  // A VALIDATION EXCEPTION WILL BE THROWN BY COMMIT                 session.Transaction.Commit();                              } 

The ModelBaseEventListener uses the NexPort FluentValidationFactory to create an instance of the proper validator. The factory stores singleton validator references in a ConcurrentDictionary in order to mitigate the performance hit incurred by constructing new validators.

In my next article, I will discuss using Fluent Validation to validate model entities on the client side. In the meantime, please check out the Fluent Validation Documentation.

About NexPort Solutions Group

NexPort Solutions Group is a division of Darwin Global, LLC, a systems and software engineering company that provides innovative, cost-effective training solutions and support for federal, state and local government, as well as the private sector.
0 Comments

NexPort Campus to Release Version 4.0.2

12/7/2011

0 Comments

 
OKLAHOMA CITY – Dec. 7, 2011 – NexPort Solutions will release the latest version of NexPort Campus Jan. 1, 2012. NexPort Campus version 4.0.2 includes new reporting fields, the ability to share or copy test banks between organizations and suborganizations and section blogging capability.  

NexPort Campus is a secure, hosted learning and knowledge management system. NexPort Campus also supports interactive engagement within learning communities through the use of videos, an individual calendar, shared documents, organization-wide webpages and threaded discussions. Additional system features include data interoperability with external systems, secure digital libraries with subscriber-only access and an integrated Student Information System (SIS).

NexPort Campus also allows clients to become online providers of user-customized, on-demand training and education services. Clients operate within their own branded sites to deliver their specialized services independently of each other. Customers may subdivide their sites to establish and manage subordinate secure sites for their customers, subsidiaries or divisions. Each site provides privacy protection and security. Custom sites can be setup with Secure Sockets Layer technology (128-bit encryption) and a custom domain.

About NexPort Solutions


NexPort Solutions is a division of Darwin global, a software engineering company that provides innovative, cost-effective training solutions and support for federal, state and local government, as well as the private industry.

0 Comments

    Archives

    December 2014
    November 2013
    December 2011

    Categories

    All
    Engineering

    RSS Feed

Products | Partners | News | About Us | Contact | Support | Careers                                 Copyright ©2014 Nexport Solutions | Terms of Use
                                                                                                                                                     All images used according to license permissions.