Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Threading;
- namespace Threads_B
- {
- class Program
- {
- static int quanti = 100000000;
- static double[] v = new double[quanti];
- static double somma = 0;
- static void CalcolaSomma()
- {
- int iterazioni = 20;
- for (int volte = 0; volte < iterazioni; volte++)
- {
- Console.WriteLine($"Iterazione {volte}");
- somma = 0;
- for (int i = 0; i < quanti; i++) somma += v[i];
- }
- }
- static void Main(string[] args)
- {
- Random generatore = new Random();
- for (int i = 0; i < quanti; i++) v[i] = generatore.NextDouble() * 10;
- DateTime start = DateTime.Now;
- CalcolaSomma();
- Console.WriteLine($"Somma: {somma}");
- DateTime end = DateTime.Now;
- Console.WriteLine((end - start).TotalMilliseconds)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement