国产精品久久国产精品99 gif,国产精品久久久久久久伊一,中文字幕在线观看,天美传媒精品1区2区3区,亚洲情a成黄在线观看动漫尤物 ,久久精品国产久精国产一老狼,亚洲殴美国产日韩av,中文无码字幕中文有码字幕

                南京軟件定制開發

                南京傾心軟件歡迎您訪問本站

                13605185909

                新聞資訊

                NEWS CENTER
                欄目導航

                企業定制軟件之C#與C++混合編程及性能分析

                發布時間:Mar 01, 2022         已有 人瀏覽
                C#C++混合編程及性能分析
                概要:
                眾所周知, ?
                C#做界??C++開發效率要?得多, 但在有性能問題的情況下不得不將部分模塊使?C++, 這時就需要使?C#C++混合
                編程。 本?給出了兩種混合編程的?法以及性能對?。
                開發環境:

                ThinkPad T430 i5-3230M 2.6G 8GWin7 64BitVS2013C++開發設置) , C++C#都采?x64平臺, 性能驗證使?Release版本。
                測試純
                C++項?性能:
                1. 新建空解決?案: ?件|新建|項?|已安裝|模板|其他項?類型|Visual Studio解決?案|空?解決?案
                2. 新建PureCpp項?: 右擊解決?案|添加|新建項?|已安裝|Visual C++|Win32控制臺程序, 按缺省設置?成項?
                3. 在配置管理器中新建x64平臺, 刪除其他平臺
                4. 新建CppFunction, 并添加測試代碼, 完整代碼如下, 程序結果: Result: 1733793664 Elapsed: 109
                // CppFunction.h
                #pragma once
                class CppFunction
                {
                p
                ublic
                :
                CppFunction(){}
                ~CppFunction(){}

                int TestFunc(int a, int b);
                };

                // CppFunction.cpp
                #include "stdafx.h"
                #include "CppFunction.h"
                class CCalc
                {
                p
                ublic
                :
                CCalc(
                int a, int b)
                {
                m_a = a;
                m_b = b;
                }
                i
                nt
                Calc()
                {

                if (m_a % 2 == 0){
                return m_a + m_b;
                }
                if
                (m_b % 2 == 0){
                return m_a - m_b;
                }
                r
                eturn
                m_b - m_a;
                }

                private:
                int m_a;
                int m_b;
                };

                int CppFunction::TestFunc(int a, int b)
                {
                CCalc calc(a, b);

                return calc.Calc();
                }
                /
                / PureCpp.cpp :
                定義控制臺應?程序的??點。
                //
                #include "stdafx.h"
                #include <iostream>
                #include <windows.h>
                #include
                "CppFunction.h"
                using namespace std;
                int _tmain(int argc, _TCHAR* argv[])
                {
                DWORD start = ::GetTickCount();
                CppFunction cppFunction;

                int result = 0;
                for (int i = 0; i < 10000; i++){
                for (int j = 0; j < 10000; j++){
                result += cppFunction.TestFunc(i, j);
                }
                }D
                WORD end = ::GetTickCount();
                cout <<
                "Result: " << result << " Elapsed: " << end - start << endl;
                return 0;
                }
                V
                iew Code

                測試純Csharp項?性能:
                1. 新建PureCsharp項?: 右擊解決?案|添加|新建項?|已安裝|其他語?|Visual C#|控制臺應?程序, 按缺省設置?成項?
                2. 在配置管理器中新建x64平臺, 刪除其他平臺, 去掉【創建新的解決?案平臺】 勾選, 否則會報x64平臺已經存在
                3. C++項?中的代碼復制過來稍作改動, 完整代碼如下, 程序結果: Result: 1733793664 Elapsed: 729
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                namespace PureCsharp
                {

                class CCalc
                {

                public CCalc(int a, int b)
                {
                m_a = a;
                m_b = b;
                }
                p
                ublic int
                Calc()
                {

                if (m_a % 2 == 0)
                {

                return m_a + m_b;
                }
                if
                (m_b % 2 == 0)
                {

                return m_a - m_b;
                }
                r
                eturn
                m_b - m_a;
                }
                p
                rivate int
                m_a;
                private int m_b;
                }
                c
                lass
                CppFunction
                {

                public int TestFunc(int a, int b)
                {
                CCalc calc =
                new CCalc(a, b);
                return calc.Calc();
                }
                }
                c
                lass
                Program
                {

                static void Main(string[] args)
                {
                DateTime start = System.DateTime.Now;
                CppFunction cppFunction =
                new CppFunction();
                int result = 0;
                for (int i = 0; i < 10000; i++){
                for (int j = 0; j < 10000; j++){
                result += cppFunction.TestFunc(i, j);
                }
                }D
                ateTime end = System.DateTime.Now;

                System.Console.WriteLine("Result: " + result + " Elapsed: " + (end - start).Milliseconds);
                }
                }
                }
                V
                iew Code

                性能分析:
                從上?的對?可以看出, 同樣的功能,
                C#的耗時?乎是C++7倍, 這個例??的主要原因是, C++可以使??效的棧內存對象
                CCalc) , ?C#所有對象只能放在托管堆中。
                托管
                C++混合?式:
                1. 新建C#控制臺項?, 命名為BenchCsharp, 使?它來調?C++項?, 修改?成?錄為: ..\x64\Release\
                2.
                新建C++DLL項?, 命名為DLLCpp, 選擇空項?, ?成成功, 但由于是空項?, 不會真正?成dll?件
                3. DLLCpp為空項?時, 在BenchCsharp中可以成功添加引?, 但當DLLCpp中添加類后, 就不能成功添加引?了, 已經添加的引?
                也會顯?警告

                4. 修改DLLCpp項?屬性, 右擊項?|屬性|配置屬性|常規|公共語?運?時?持, 修改后就可以成功引?了
                5. DLLCpp中添加CppFunction類, 并復制代碼, 完整代碼如下, 程序結果: Result: 1733793664 Elapsed: 405
                // CppFunction.h
                #pragma once
                public ref class CppFunction
                {
                p
                ublic
                :
                CppFunction(){}
                ~CppFunction(){}

                int TestFunc(int a, int b);
                };

                // CppFunction.cpp
                #include "CppFunction.h"
                class CCalc
                {
                p
                ublic
                :
                CCalc(
                int a, int b)
                {
                m_a = a;
                m_b = b;
                }
                i
                nt
                Calc()
                {

                if (m_a % 2 == 0){
                return m_a + m_b;
                }
                if
                (m_b % 2 == 0){
                return m_a - m_b;
                }
                r
                eturn
                m_b - m_a;
                }

                private:
                int m_a;
                int m_b;
                };

                int CppFunction::TestFunc(int a, int b)
                {
                CCalc calc(a, b);

                return calc.Calc();
                }
                V
                iew Code

                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Text;
                using System.Threading.Tasks;
                namespace BenchCsharp
                {

                class Program
                {

                static void Main(string[] args)
                {
                DateTime start = System.DateTime.Now;
                CppFunction cppFunction =
                new CppFunction();
                int result = 0;
                for (int i = 0; i < 10000; i++)
                {

                for (int j = 0; j < 10000; j++)
                {
                result += cppFunction.TestFunc(i, j);
                }
                }D
                ateTime end = System.DateTime.Now;
                System.Console.WriteLine(
                "Result: " + result + " Elapsed: " + (end - start).Milliseconds);
                }
                }
                }
                V
                iew Code

                性能分析:
                使?混合編程后, 性能得到了?定程度的提升, 但?起單純的
                C++項?, 還是差了很多
                C#主函數中的邏輯轉移到DLLCpp項?中, 即添加如下的static?法, C#中只要調?該?法, 程序結果: Result: 1733793664
                Elapsed: 405

                int CppFunction::Test()
                {
                DWORD start = ::GetTickCount();
                CppFunction cppFunction;

                int result = 0;
                for (int i = 0; i < 10000; i++){
                for (int j = 0; j < 10000; j++){
                result += cppFunction.TestFunc(i, j);
                }
                }D
                WORD end = ::GetTickCount();
                cout <<
                "Result: " << result << " Elapsed: " << end - start << endl;
                return result;
                }
                V
                iew Code

                并沒有變得更快, 估計是當使?【公共語?運?時?持】 ?式編譯C++時, 不能發揮C++的性能優勢
                DLLImport混合?式:
                1. 新建?空的C++DLL項?, 命名為NativeDLLCpp
                2.
                CppFunction類從PureCpp中復制過來
                3. 代碼如下, 運?結果: Result: 1733793664 Elapsed: 125
                // NativeDLLCpp.cpp : 定義 DLL 應?程序的導出函數。
                //
                #include "stdafx.h"
                #include <iostream>
                #include <windows.h>
                #include
                "CppFunction.h"
                using namespace std;
                #ifdef __cplusplus

                #define TEXPORT extern "C" _declspec(dllexport)
                #else
                #define
                TEXPORT _declspec(dllexport)
                #endif
                TEXPORT int Test()
                {

                DWORD start = ::GetTickCount();
                CppFunction cppFunction;

                int result = 0;
                for (int i = 0; i < 10000; i++){
                for (int j = 0; j < 10000; j++){
                result += cppFunction.TestFunc(i, j);
                }
                }D
                WORD end = ::GetTickCount();
                cout <<
                "Result: " << result << " Elapsed: " << end - start << endl;
                return result;
                }
                V
                iew Code

                public class NativeDLLCpp
                {
                [DllImport(
                "NativeDLLCpp.dll")]
                public static extern int Test();
                }
                c
                lass
                Program
                {

                static void Main(string[] args)
                {
                DateTime start = System.DateTime.Now;

                int result = NativeDLLCpp.Test();
                DateTime end = System.DateTime.Now;
                System.Console.WriteLine(
                "Result: " + result + " Elapsed: " + (end - start).Milliseconds);
                }
                }

                View Code
                性能分析:
                跟純
                C++項?性能?乎?致。
                項?依賴項需要?動設置。
                實現聯調的?法: 修改
                C#項?屬性|調試|啟?本機代碼調試

                Copyright © 2020-2022 南京傾心軟件技術有限公司 版權所有     蘇ICP備2020070309號-1
                QQ在線咨詢
                13605185909
                返回頂部
                主站蜘蛛池模板: 国产微拍一区二区三区四区| 中文字幕无码日韩欧免费软件| 国产婷婷色综合av性色av| 亚洲男人的天堂一区二区| 天堂a无码a无线孕交| 久久九九久精品国产| 午夜无码区在线观看亚洲| 蜜桃网址| 亚洲国产av一区二区三区四区| 永久免费观看美女裸体视频的网站 | 日韩少妇内射免费播放18禁裸乳| av在线播放日韩亚洲欧| 精品国产成人午夜福利| 午夜肉伦伦影院| 国产一卡2卡3卡4卡精品| 欧美性猛交xxxx免费看| 国产高清在线精品一区不卡| 亚洲人成无码网www电影麻豆| 99久久久无码国产精品免费| 久久综合给合综合久久| 五月婷婷六月丁香动漫| 最新亚洲人成网站在线观看| 免费人成网站在线视频| 亚洲精品卡一卡2卡3卡4卡| 99热久久这里只有精品| 男女性潮高清免费网站| 在线播放偷拍一区精品| 日韩人妻无码一区二区三区| 亚洲成av人无码综合在线观看| 久久综合久久香蕉网欧美| 无码伊人久久大杳蕉中文无码| 欧美牲交a欧美牲交aⅴ| 果冻传媒2021精品一区| 久久这里都是精品一区| 99久久精品国产第一页| 亚洲中文有码字幕日本第一页 | 人妻丰满熟妇AV无码区APP | 四虎在线播放亚洲成人| 日本高清va在线播放| 国产午夜福利精品久久不卡| 国产高清在线精品一本大道|