This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class WebForm1 : System.Web.UI.Page | |
{ | |
static string strOut = ""; | |
static string strOut1 = ""; | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Response.Write("Start with Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime StartTPL = System.DateTime.Now; | |
Parallel.For(0, 100000, x => PrintAllTPL()); | |
Response.Write("End with Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime EndTPL = System.DateTime.Now; | |
Response.Write("Start with out Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime StartNoTPL = System.DateTime.Now; | |
PrintAll(); | |
Response.Write("End with out Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime EndNoTPL = System.DateTime.Now; | |
Response.Write("Time with Task Parallel Library: " + EndTPL.Subtract(StartTPL) + "<br />"); | |
Response.Write("Time without Task Parallel Library: " + EndNoTPL.Subtract(StartNoTPL) + "<br />"); | |
} | |
private static void PrintAll() | |
{ | |
for (int i = 0; i < 100000; i++) | |
{ | |
strOut = strOut + "a" + "\n"; | |
} | |
} | |
private static void PrintAllTPL() | |
{ | |
strOut1 = strOut1 + "a" + "\n"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class XMLread : System.Web.UI.Page | |
{ | |
public static string[] stringList = { "dog", "cat", "bird" }; | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Response.Write("Start with Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime StartTPL = System.DateTime.Now; | |
Parallel.For(0, 100000, x => PrintAllTPL()); | |
Response.Write("End with Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime EndTPL = System.DateTime.Now; | |
Response.Write("Start with out Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime StartNoTPL = System.DateTime.Now; | |
PrintAll(); | |
Response.Write("End with out Task Parallel Library" + System.DateTime.Now.ToString() + "<br />"); | |
DateTime EndNoTPL = System.DateTime.Now; | |
Response.Write("Task Parallel Library: " + EndTPL.Subtract(StartTPL) + "<br />"); | |
Response.Write("No Task Parallel Library: " + EndNoTPL.Subtract(StartNoTPL) + "<br />"); | |
} | |
private static void PrintAll() | |
{ | |
foreach (string s in stringList) | |
{ | |
var result = s; | |
Console.WriteLine("Initial string: {0}, Result : {1} ", s, result); | |
} | |
} | |
private static void PrintAllTPL() | |
{ | |
Parallel.ForEach(stringList, s => | |
{ | |
var result = s; | |
Console.WriteLine("Initial string {0}, Result : {1} ", s, result); | |
}); | |
} | |
} |