Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Speed test for email text replacements
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Diagnostics; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Text; namespace Rextester { public static class StringExtension { //private static Dictionary<string, string> _replacements = new Dictionary<string, string>(); static StringExtension() { } public static string clean(this string s, Dictionary<string, string> replacements) { foreach (string to_replace in replacements.Keys) { s = s.Replace(to_replace, replacements[to_replace]); } return s; } public static string StringBuilderclean(string data, Dictionary<string, string> values) { StringBuilder sb = new StringBuilder(data, data.Length * 2); foreach (string k in values.Keys) { sb.Replace(k, values[k]); } return sb.ToString(); } public static string Regexclean(string input, Dictionary<string, string> replacements) { var regex = new Regex(String.Join("|",replacements.Keys.Select(k => Regex.Escape(k)))); var replaced = regex.Replace(input,m => replacements[m.Value]); return replaced; } } public class Program { public static void Main(string[] args) { var input = @"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\ <html xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>\ <head>\ <title></title>\ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\ <style type='text/css'>\ body, .maintable {\ height: 100% !important;\ width: 100% !important;\ margin: 0;\ padding: 0;\ font-family: arial, helvetica, sans-serif;\ }\ \ a {\ color: #555555;\ text-decoration: none;\ }\ \ a.black {\ color: #555555;\ }\ \ a.white {\ color: #ffffff;\ }\ \ img, a img {\ border: 0;\ outline: none;\ text-decoration: none;\ }\ \ .imagefix {\ display: block;\ }\ \ p {\ margin-top: 0;\ margin-right: 0;\ margin-left: 0;\ padding: 0;\ }\ \ .ReadMsgBody {\ width: 100%;\ }\ \ .ExternalClass {\ width: 100%;\ }\ \ .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {\ line-height: 100%;\ }\ \ img {\ -ms-interpolation-mode: bicubic;\ }\ \ body, table, td, p, a, li, blockquote {\ -ms-text-size-adjust: 100%;\ -webkit-text-size-adjust: 100%;\ }\ </style>\ <style type='text/css'>\ @media only screen and (max-width: 600px) {\ .rtable {\ width: 100% !important;\ table-layout: fixed;\ }\ \ .rtable tr {\ height: auto !important;\ display: block;\ }\ \ .contenttd {\ max-width: 100% !important;\ display: block;\ }\ \ .contenttd:after {\ content: '';\ display: table;\ clear: both;\ }\ \ .hiddentds {\ display: none;\ }\ \ .imgtable, .imgtable table {\ max-width: 100% !important;\ height: auto;\ float: none;\ margin: 0 auto;\ }\ \ .imgtable.btnset td {\ display: inline-block;\ }\ \ .imgtable img {\ /*width: 100%;*/\ height: auto;\ display: block;\ }\ \ table {\ float: none;\ table-layout: fixed;\ }\ }\ </style>\ <!--[if gte mso 9]>\ <xml>\ <o:OfficeDocumentSettings>\ <o:AllowPNG/>\ <o:PixelsPerInch>96</o:PixelsPerInch>\ </o:OfficeDocumentSettings>\ </xml>\ <![endif]-->\ </head>\ <body style='overflow: auto; padding:0; margin:0; font-size: 14px; font-family: arial, helvetica, sans-serif; cursor:auto; background-color:#F0F0F0'>\ <table style='overflow: auto; padding: 0; margin: 0; font-size: 14px; font-family: arial, helvetica, sans-serif; cursor: auto; background-color: #f0f0f0;' width='100%' cellspacing='0' cellpadding='0' bgcolor='#F0F0F0'>\ <tbody>\ <tr>\ <td style='font-size: 0px; height: 20px; line-height: 0;'> </td>\ </tr>\ <tr>\ <td valign='top'>\ <table class='rtable' style='width: 600px; margin: 0px auto; background-color: #ffffff;' border='0' width='600' cellspacing='0' cellpadding='0' align='center'>\ <tbody>\ <tr>\ <td style='background-color: #ffffff; padding: 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='left'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 75%; line-height: 0;'> </td>\ <td style='font-size: 0px; height: 0px; width: 25%; line-height: 0;'> </td>\ </tr>\ <tr style='height: 10px; width: 100%;'>\ <th style='font-weight: normal; text-align: left; background-color: #ffffff; color: #555555; padding: 5px 15px 5px 10px; width: 75%; vertical-align: middle;'><!-- [if gte mso 12]>\ <table cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='left'>\ <![endif]-->\ <table style='margin-left: 0px; margin-right: auto;' border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='padding: 2px 2px 2px 2px;' align='center'>\ <table border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='background-color: transparent;'><a href='https://www.sworder.co.uk'> <img style='display: block;' src='https://www.sworder.co.uk/imagestore/Email%20Templates/sworders-logo-strap-black-300.png?v=636379594834000000' alt='' width='135' height='55' hspace='0' vspace='0' /> </a></td>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ </tbody>\ </table>\ <!-- [if gte mso 12]>\ </td></tr></table>\ <![endif]--></th>\ <th style='font-weight: normal; text-align: left; background-color: #ffffff; color: #555555; padding: 5px 0px 5px 15px; vertical-align: middle;'><!-- [if gte mso 12]>\ <table cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='left'>\ <![endif]-->\ <table style='margin-left: 0px; margin-right: auto;' border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='padding: 2px 2px 2px 2px;' align='center'>\ <table border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='background-color: transparent; color: #555555;' align='center'><a href='https://www.sworder.co.uk/account'><img style='display: block;' src='https://www.sworder.co.uk/imagestore/Email%20Templates/account.png?v=636362367452630000' alt='' width='28' height='19' hspace='0' vspace='0' /></a>\ <p style='padding-top: 10px;'><a class='black' href='https://www.sworder.co.uk/account'>MY ACCOUNT</a></p>\ </td>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ </tbody>\ </table>\ <!-- [if gte mso 12]>\ </td></tr></table>\ <![endif]--></th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td class='contenttd' style='background-color: #7da6b5; padding: 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='center'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 100%; line-height: 0; mso-line-height-rule: exactly;'> </td>\ </tr>\ <tr style='height: 20px;'>\ <th class='contenttd' style='vertical-align: top; font-weight: normal; text-align: left; background-color: transparent; padding: 20px 15px 20px 15px;'>\ <p style='font-size: 24px; line-height: 24px; margin-bottom: 0; font-family: geneve, arial, helvetica, sans-serif; margin-top: 0px; color: #ffffff; background-color: transparent; mso-line-height-rule: exactly;' align='center'>INVOICE PAID</p>\ </th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td class='contenttd' style='background-color: #ffffff; padding: 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='center'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 100%; line-height: 0; mso-line-height-rule: exactly;'> </td>\ </tr>\ <tr style='height: 20px;'>\ <th class='contenttd' style='vertical-align: top; font-weight: normal; text-align: left; background-color: #ffffff; padding: 20px 15px 20px 15px;'>\ <p style='font-size: 14px; line-height: 18px; margin-bottom: 0; font-family: geneve, arial, helvetica, sans-serif; margin-top: 0px; color: #000000; background-color: transparent; mso-line-height-rule: exactly;' align='left'>Dear client, <br /><br />Thank you for the payment of your invoice. The details of the transaction are shown below.</p>\ <h2>INVOICE PAYMENT DETAILS</h2>\ <table width='100%'>\ <tbody>\ <tr>\ <td><strong>Payment from:</strong><br />[address]</td>\ <td><strong>Invoice number:</strong><br />[invoice-number]<br /><strong>Invoice paid date:</strong><br />[invoice-paid-date]</td>\ <td rowspan='2' align='center'><a href='[invoice-pdf-url]'><img src='https://www.sworder.co.uk/imagestore/Email%20Templates/pdf-icon-transparent.png?v=636391835812230000' width='141' height='166' /></a><br /><a href='[invoice-pdf-url]'>Click here</a> to download <br />a PDF of your invoice</td>\ </tr>\ <tr>\ <td><strong>Invoice total (inc VAT):</strong> <br /><strong>Surcharge fee:</strong><br /><strong>Invoice total paid:</strong> </td>\ <td align='right'><strong><br /></strong>£[invoice-amount]<br />£[invoice-surcharge]<br />£[invoice-total]<strong><br /></strong></td>\ </tr>\ <tr>\ <td colspan='3'><strong><br />Authorisation code:</strong> [payment-authcode]<br /><strong>Reference code:</strong> [payment-identifier]</td>\ </tr>\ </tbody>\ </table>\ <p style='font-size: 14px; line-height: 18px; margin-bottom: 0; font-family: geneve, arial, helvetica, sans-serif; margin-top: 0px; color: #000000; background-color: transparent; mso-line-height-rule: exactly;' align='left'><br /><strong>Packing and postage<br /></strong><br />Sworders are happy to guide you through package and postage needs. <br /><br />Sworders</p>\ </th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td class='contenttd' style='background-color: #7da6b5; color: #ffffff; padding: 0px 0px 5px 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='left'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 75%; line-height: 0;'> </td>\ <td style='font-size: 0px; height: 0px; width: 25%; line-height: 0;'> </td>\ </tr>\ <tr style='height: 10px;'>\ <th class='contenttd' style='vertical-align: top; font-weight: normal; text-align: left; background-color: transparent; padding: 5px;'>\ <div style='text-align: left; padding: 10px;'>\ <table class='imgtable imgTable' style='display: inline-block;' border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='padding-right: 5px;'><a href='https://www.sworder.co.uk'> <img style='display: block;' src='https://www.sworder.co.uk/imagestore/Email%20Templates/sworders-logo-strap-white-300.png?v=636379096306570000' alt='' width='162' height='55' hspace='0' vspace='0' /> </a></td>\ </tr>\ </tbody>\ </table>\ </div>\ </th>\ <th class='contenttd' style='vertical-align: top; font-weight: normal; text-align: left; background-color: transparent; padding: 5px;'>\ <div style='text-align: right; padding: 10px;'>\ <table class='imgtable imgTable' style='display: inline-block;' border='0' cellspacing='0' cellpadding='0'>\ <tbody>\ <tr>\ <td style='color: #ffffff; padding-right: 5px; text-align: right;' colspan='4'>\ <p class='font-size: 14px; line-height: 18px;'>Connect with us</p>\ </td>\ </tr>\ <tr>\ <td style='padding-right: 10px;'><a href='https://www.facebook.com/swordersfineart/' target='_blank' rel='noopener noreferrer'><img style='display: block;' title='Facebook' src='https://www.sworder.co.uk/imagestore/Email%20Templates/facebook-icon.png?v=636378900234600000' alt='Facebook' width='26' height='26' /></a></td>\ <td style='padding-right: 10px;'><a href='https://twitter.com/swordersfineart' target='_blank' rel='noopener noreferrer'><img style='display: block;' title='Twitter' src='https://www.sworder.co.uk/imagestore/Email%20Templates/twitter-icon.png?v=636378900234630000' alt='Twitter' width='26' height='26' /></a></td>\ <td style='padding-right: 10px;'><a href='https://uk.pinterest.com/swordersfineart/' target='_blank' rel='noopener noreferrer'><img style='display: block;' title='Pinterest' src='https://www.sworder.co.uk/imagestore/Email%20Templates/pinterest-icon.png?v=636378900234630000' alt='Pinterest' width='26' height='26' /></a></td>\ <td><a href='https://www.instagram.com/swordersfineart/' target='_blank' rel='noopener noreferrer'><img style='display: block;' title='Linkedin' src='https://www.sworder.co.uk/imagestore/Email%20Templates/instagram.png?v=636378900234600000' alt='Instagram' width='26' height='26' /></a></td>\ </tr>\ </tbody>\ </table>\ </div>\ </th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td class='contenttd' style='background-color: #7da6b5; color: #ffffff; padding: 1px 0px 1px 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='left'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 600px; line-height: 0; mso-line-height-rule: exactly;'> </td>\ </tr>\ <tr style='height: 10px;'>\ <th class='contenttd' style='font-weight: normal; text-align: left; background-color: transparent; color: #ffffff; padding: 1px 15px; vertical-align: top;'>\ <p style='font-size: 12px; margin-bottom: 1em; font-family: arial, helvetica, sans-serif; margin-top: 0px; line-height: 12px; background-color: transparent; mso-line-height-rule: exactly;' align='center'><a class='white' href='https://www.sworder.co.uk/contact-stansted'>Stansted Saleroom</a> - telephone 01279 817778 <br /> <a class='white' href='mailto:auctions@sworder.co.uk'>auctions@sworder.co.uk</a> <br /><br /> <a class='white' href='https://www.sworder.co.uk/contact-hertford'>Hertford Office</a> - telephone 01992 583 508 <br /> <a class='white' href='mailto:hertfordoffice@sworder.co.uk'>hertfordoffice@sworder.co.uk</a> <br /><br />Sworders Kent - telephone 01732 757 675 <br /> <a class='white' href='mailto:kent@sworder.co.uk'>kent@sworder.co.uk</a></p>\ </th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td class='contenttd' style='background-color: #ececec; color: #555555; padding: 10px 0px 10px 0px;'>\ <table style='width: 100%;' cellspacing='0' cellpadding='0' align='left'>\ <tbody>\ <tr class='hiddentds'>\ <td style='font-size: 0px; height: 0px; width: 600px; line-height: 0; mso-line-height-rule: exactly;'> </td>\ </tr>\ <tr style='height: 10px;'>\ <th class='contenttd' style='font-weight: normal; text-align: left; background-color: transparent; color: #555555; padding: 1px 15px; vertical-align: top;'>\ <p style='font-size: 12px; margin-bottom: 1em; font-family: arial, helvetica, sans-serif; margin-top: 0px; line-height: 12px; background-color: transparent; mso-line-height-rule: exactly;' align='left'>We are sending this email to <a class='black' href='mailto:[email]'>[email]</a>. <br /><br /> You are receiving this email because you have signed up to receive sale notice emails when registering with <a class='black' href='https://www.sworder.co.uk'>www.sworder.co.uk</a>. <br /><br /> Please see our buying conditions <a class='black' href='https://www.sworder.co.uk/terms-and-conditions'>here</a>.</p>\ </th>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ </tbody>\ </table>\ </td>\ </tr>\ <tr>\ <td style='font-size: 0px; height: 8px; line-height: 0;'> </td>\ </tr>\ </tbody>\ </table>\ </body>\ </html>\"; int count; int repeat = 1000; Console.WriteLine("Repeats: " + repeat); string output1="1"; Dictionary<string, string> replacements = new Dictionary<string, string>(); replacements["[full-name]"] = "My [full-name] Here"; replacements["[first-name]"] = "My [first-name] Here"; replacements["[email]"] = "My [email] Here"; replacements["[address]"] = "My [address] Here"; replacements["[auction-name]"] = "My [auction-name] Here"; replacements["[auction-number]"] = "My [auction-number] Here"; replacements["[auction-date]"] = "My [auction-date] Here"; replacements["[payment-identifier]"] = "My [payment-identifier] Here"; replacements["[payment-authcode]"] = "My [payment-authcode] Here"; replacements["[invoice-number]"] = "My [invoice-number] Here"; replacements["[invoice-amount]"] = "My [invoice-amount] Here"; replacements["[invoice-surcharge]"] = "My [invoice-surcharge] Here"; replacements["[invoice-total]"] = "My [invoice-total] Here"; replacements["[invoice-paid-date]"] = "My [invoice-paid-date] Here"; replacements["[invoice-pdf-url]"] = "My [invoice-pdf-url] Here"; // etc... string output4 = "4"; Stopwatch watch4 = Stopwatch.StartNew(); for (count=repeat;count >=0;count--) output4 = Rextester.StringExtension.Regexclean(input, replacements); //Console.WriteLine( Rextester.StringExtension.Regexclean(input, replacements)); watch4.Stop(); double stringMilliseconds4 = watch4.ElapsedMilliseconds; Console.WriteLine("Regex replace with dictionary: " + stringMilliseconds4); Stopwatch watch1 = Stopwatch.StartNew(); for (count=repeat;count >=0;count--) output1 = Rextester.StringExtension.clean(input, replacements); //Console.WriteLine( Rextester.StringExtension.clean(input, replacements)); watch1.Stop(); double stringMilliseconds = watch1.ElapsedMilliseconds; Console.WriteLine("String replace with dictionary: " + stringMilliseconds); string output2="2"; Stopwatch watch2 = Stopwatch.StartNew(); for (count=repeat;count >=0;count--) output2 = input.Replace("[full-name]", "My [full-name] Here") .Replace("[first-name]", "My [first-name] Here") .Replace("[email]", "My [email] Here") .Replace("[address]", "My [address] Here") .Replace("[auction-name]", "My [auction-name] Here") .Replace("[auction-number]", "My [auction-number] Here") .Replace("[auction-date]", "My [auction-date] Here") .Replace("[payment-identifier]", "My [payment-identifier] Here") .Replace("[payment-authcode]", "My [payment-authcode] Here") .Replace("[invoice-number]", "My [invoice-number] Here") .Replace("[invoice-amount]", "My [invoice-amount] Here") .Replace("[invoice-surcharge]", "My [invoice-surcharge] Here") .Replace("[invoice-total]", "My [invoice-total] Here") .Replace("[invoice-paid-date]", "My [invoice-paid-date] Here") .Replace("[invoice-pdf-url]", "My [invoice-pdf-url] Here"); watch2.Stop(); double stringMilliseconds2 = watch2.ElapsedMilliseconds; Console.WriteLine("String replace with inline code:" + stringMilliseconds2); string output3="3"; Stopwatch watch3 = Stopwatch.StartNew(); for (count=repeat;count >=0;count--) output3 = Rextester.StringExtension.StringBuilderclean(input, replacements); watch3.Stop(); double stringMilliseconds3 = watch3.ElapsedMilliseconds; Console.WriteLine("Stringbuilder with dictionary: " + stringMilliseconds3); Console.WriteLine(output1 == output2 ? "1 and 2 match" : "1 and 2 don't match"); Console.WriteLine(output2 == output3 ? "2 and 3 match" : "2 and 3 don't match"); Console.WriteLine(output3 == output4 ? "3 and 4 match" : "3 and 4 don't match"); Console.WriteLine(output1 == output3 ? "1 and 3 match" : "1 and 3 don't match"); Console.WriteLine(output1 == output4 ? "1 and 4 match" : "1 and 4 don't match"); } } }
run
|
edit
|
history
|
help
0
Merge Sort
findrotations
ternary function
Code Challenege
Delegate test lambda
Random number generator with IF
toplam
Regex fórum 01
OneDrive Direct Download Generator
Reverse Number