C# 写的 CPU 浮点运算测试工具.并且还有获取CPU种种数据的方法(图)(代码)

 

此工具LUYIKK 编写

 

 

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;
using  System.Threading;
using  System.Management;



namespace  WindowsApplication1
{
    
public delegate void whowmess(long e);

    
public partial class Form1 : Form
    
{
        
public event whowmess news;

        
public Form1()
        
{
            InitializeComponent();

            news 
+= new whowmess(Form1_news);
        }


        
void Form1_news(long e)
        
{
            
this.label2.BeginInvoke(new System.EventHandler(UpdateUI), e);

        }



        
private void UpdateUI(object o, System.EventArgs e)
        
{

            
this.label2.Text = (2500000000 / burs).ToString() + "";

            
this.label1.Text = burs.ToString() + "微秒";

        }

        
long burs = 0;

        
private void button1_Click(object sender, EventArgs e)
        
{
            burs 
= 0;

            Thread a 
= new Thread(new ThreadStart(strat));
            a.Start();

            Thread b 
= new Thread(new ThreadStart(strat));
            b.Start();

      

        }



        
private void strat()
        
{



            
for (int j = 0; j < 5; j++)
            
{


                
long f = DateTime.Now.Ticks;

                
double c = 100000.123;
                
double b = 200000.021;
                
double ef = 300000.321;

                
for (int i = 0; i < 10000000; i++)
                
{
                    ef 
= c * b + ef / c - b;

                }


                
long g = DateTime.Now.Ticks;


                
long kl = g - f;

                burs 
+= kl;

            }


            
if (news != null)
            
{
                news(burs);
            }



        }



        
private void timer1_Tick(object sender, EventArgs e)
        
{

        }


        
private void label1_Click(object sender, EventArgs e)
        
{

        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            
int k = 0;
            String MyInfo 
= "CPU型号:";

            ManagementObjectSearcher MySearcher 
= new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                MyInfo 
+= "   " + String.Format("CPU" + k.ToString() + " : " + MyObject["Name"].ToString());
               
            }



            
this.label6.Text = MyInfo;


            k 
= 0;
            String MyInfo2 
= "CPU的最大时钟频率:";
           
            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                
try
                
{
                    MyInfo2 
+= "   " + String.Format("CPU" + k.ToString() + " : " + MyObject["MaxClockSpeed"].ToString());
                   
                }

                
catch { MyInfo2 = "CPU的最大时钟频率:无法获取"; }
            }


            
this.label7.Text = MyInfo2;

            k 
= 0;
            String MyInfo3 
= "CPU地址宽度:";

            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                
try
                
{
                    MyInfo3 
+= "   " + String.Format("CPU" + k.ToString() + " : " + MyObject["AddressWidth"].ToString());

                }

                
catch { MyInfo3 = "CPU地址宽度::无法获取"; }
            }


            
this.label8.Text = MyInfo3;

            String MyInfo4 
= "CPU数据宽度:";

            k 
= 0;
            
            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                
try
                
{
                    MyInfo4 
+= "   " + String.Format("CPU" + k.ToString() + " : " + MyObject["AddressWidth"].ToString());

                }

                
catch { MyInfo4 = "CPU数据宽度:::无法获取"; }
            }


            
this.label9.Text = MyInfo4;

            String MyInfo5 
= "CPU的当前电压:";
            k 
= 0;
            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                
try
                
{
                    
double x = double.Parse(MyObject["CurrentVoltage"].ToString())/10;

                    MyInfo5 
+= "   " + String.Format("CPU" + k.ToString() + " : " + x.ToString() + "V");

                }

                
catch { MyInfo5 = "CPU的当前电压::::无法获取"; }
            }


            
this.label10.Text = MyInfo5;

            String MyInfo6 
= "CPU的二级缓存:";
            k 
= 0;

            
foreach (ManagementObject MyObject in MySearcher.Get())
            
{
                k
++;
                
try
                
{


                    MyInfo6 
+= "   " + String.Format("CPU" + k.ToString() + " : " + MyObject["L2CacheSize"].ToString() + "K");

                }

                
catch { MyInfo5 = "CPU的二级缓存:无法获取"; }
            }


            
this.label11.Text = MyInfo6;



        }

    }

}

Form1.Designer.cs

 

namespace  WindowsApplication1
{
    
partial class Form1
    
{
        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>
        
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>

        protected override void Dispose(bool disposing)
        
{
            
if (disposing && (components != null))
            
{
                components.Dispose();
            }

            
base.Dispose(disposing);
        }


        
Windows 窗体设计器生成的代码

        
private System.Windows.Forms.Button button1;
        
private System.Windows.Forms.Label label1;
        
private System.Windows.Forms.Timer timer1;
        
private System.Windows.Forms.Label label2;
        
private System.Windows.Forms.Label label3;
        
private System.Windows.Forms.Label label4;
        
private System.Windows.Forms.Label label5;
        
private System.Windows.Forms.Label label6;
        
private System.Windows.Forms.Label label7;
        
private System.Windows.Forms.Label label8;
        
private System.Windows.Forms.Label label9;
        
private System.Windows.Forms.Label label10;
        
private System.Windows.Forms.Label label11;
    }

}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值