国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C#大矩陣乘法時間的開銷

2019-11-06 06:25:53
字體:
來源:轉載
供稿:網友
利用隨機數初始化數組,并計算不同量數據所消耗的時間using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace BigArray{ class PRogram { static void Main(string[] args) { DateTime d1 = System.DateTime.Now; const long M = 500; const long N = 500; long [,] A = new long [500 , 500]; long[,] B = new long[500, 500]; var listA = new List<List> (); var listB = new List<List>(); var listC = new List<List>(); Random random = new Random(); var itemA = new List(); var itemB = new List(); var itemC = new List(); for (long i = 0; i < M; i++) { for (long j = 0; j < N; j++) { int random_x = random.Next(0, 10); A[i, j] = random_x; int random_y = random.Next(0, 10); B[i, j] = random_y; // itemC.Add(random_y*random_x ); } /* listA.Add(itemA); listB.Add(itemB); listC.Add(itemC); */ } Multiply multiply = new Multiply(); long [,]MM= multiply.MatrixMultiply (A, B); DateTime d2 = System.DateTime.Now; TimeSpan ts = d2.Subtract(d1); Console.WriteLine("program'time_spend is:{0}ms", ts.TotalMilliseconds); Console.ReadLine(); } public class Multiply { public long[,] MatrixMultiply(long[,] A, long[,] B) { int rowA = A.GetLength(0); int colA = A.GetLength(1); int rowB = B.GetLength(0); int colB = B.GetLength(1); long[,] C = new long[rowA, colB]; try { for (long i = 0; i < rowA; i++) { for (long j = 0; j < colB; j++) { C[i, j] = 0; for (long k = 0; k < colA; k++) { C[i, j] = A[i, k] * B[k, j]; } } } return C; } catch { System.Exception exp = new Exception("前者矩陣列數不等于后者矩陣行數,不能相乘!"); throw exp; } } } }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石楼县| 伊金霍洛旗| 广饶县| 河间市| 普定县| 建平县| 富蕴县| 凤城市| 宜章县| 嘉禾县| 赣榆县| 邯郸县| 馆陶县| 耒阳市| 崇左市| 彭州市| 自治县| 独山县| 阜城县| 年辖:市辖区| 临猗县| 普格县| 刚察县| 桐庐县| 汽车| 阳西县| 东城区| 拜城县| 宝鸡市| 德惠市| 乐山市| 湛江市| 奉新县| 宜兴市| 永靖县| 贵溪市| 昭平县| 海南省| 泸溪县| 沂源县| 齐河县|