Präsentation herunterladen
Veröffentlicht von:Erna Doster Geändert vor über 10 Jahren
1
Performanz-orientierte Programmierung in C# Performanzaspekte von MS
Performanz-orientierte Programmierung in C# Performanzaspekte von MS.NET Matej Ciesko Microsoft Student Partner Friedrich – Alexander Universität Erlangen – Nürnberg
2
Performanz-orientierte Programmierung in C#
Einführung Performanz-orientierte Programmierung Optimierung [Optimizing is the process of changing a program or the environment in which it runs to improve its performance.] Prozess der Optimierung: Problem identifizieren Problem evaluieren Anwenden einer Optimierungstechnik Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
3
Agenda Einführung Performanzzähler (performance counters)
Nanosekunden Timer MS.NET Profiling API MS.NET – Performanzaspekte CLR, JIT, CG Performanzaspekte bei Entwicklung mit C# Objekte (GC) Datentypen Sicherer/Unsicherer Code … Zusammenfassung
4
Performanz-orientierte Programmierung in C#
Ziele Performanzaspekte des MS.NET Messen von Performanzverhalten Schreiben vom effizienten Code (C#) Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
5
Performanz-orientierte Programmierung in C#
Einführung Beispielapplikation: Matrix – Matrix Multiplikation C = A * B Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
6
Performanzaspekte von C#
Arrays Array[index] Eliminierung der Überprüfung: Längentest im For-Header for (int i=0; i < Array.Length; i++) for (int i=0; i < Array.Length + y; i++) Array[i+6]; sum += a[i] Überprüfung Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
7
Performanzaspekte von C#
C# Zeiger Arbeiten außerhalb vom GC „Pinnen“ von Objekten zum Speicher unsafe{ fixed (type* ptr = expr) statement } Anmerkung: Compiler flag: /unsafe Code ist unsafe Nach dem statement sind alle “pinned” Objekte für den GC wieder freigegeben Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
8
Performanz-orientierte Programmierung in C#
Einführung Beispielapplikation: ??? Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
9
Performanz-orientierte Programmierung in C#
Profiling Performanzzähler Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
10
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung Fundamentale Prinzipien der Performanz-orientierten Programmierung: Performanzziele setzen Messen, messen und noch mehr messen Optimieren Profiling: Präzise Messung (von Zeit/Clock Ticks) von Hardware und/Applikation um Aussagen über Laufzeitverhalten von Applikation treffen zu können. Hardwarezähler (performance counters) Windows Performance Counters MS.NET Profiler API Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
11
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung Hardware Counters Sehr hohe zeitliche Auflösung!!! Performanzereignisse Programmcharakteristika, Speicher, pipeline stalls, branch prediction, ressource utilization CPU Profiling Hardware Ereignisdetektoren (event detectors) Ereigniszähler (event counters) Beispiel: RDTSC(Read Time Step Counter) typedef struct _int32 { __int32 i32[2] } BigInt; BigInt start_ticks, end_tickes; _asm { RDTSC mov start_ticks.int32val.i32[0], eax mov start_ticks.int32val.i32[4], edx } >2 x CPU SpeedStep Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
12
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung Windows Performance Counters MS Windows API perfmon.exe Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
13
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung .NET CLR Profiling Services speziell für Verhalten von .NET Applikationen COM – Schnittstellen: ICorProfilerCallback ICorProfilerInfo Profiler Design COM Server Komponente implementieren ICorProfilerCallback implementieren Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
14
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung .NET CLR Profiling Services set Cor_Enable_Profiling = 0x1 set Cor_Profiler={FA0C6E77-AFF4-…992C} CLR Cor_Enable_Profiling = TRUE _myProfiler CoCreateInstance ICorProfilerCallback::Initialize Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
15
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung Allocation Profiler (Demo) Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
16
Performanz-orientierte Programmierung in C#
Profiling Perf. Counters MS.NET C# Zusammenfassung Allocation Profiler Intel® VTune™ Performance Analyzer Rational® PurifyPlus for Windows Compuware® DevPartner Profiler Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
17
MS.NET Performanzaspekte
Speicherverwaltung Compiler Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
18
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung Source code Fortran C# C++ Unmanaged Component Compiler Compiler Compiler Managed code Assembly IL Code Assembly IL Code Assembly IL Code Common Language Runtime JIT Compiler Native Code Operating System Services Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
19
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung JIT (Just-In-Time) Kompilierung Ausgangspunkt Plattformunabhängiger IL Code Generelle Optimierung Constant folding, Method inlining, Loop unrolling, Common subexression elimination Optimierung zur Laufzeit Lazy code selection, cache tuning, CPU spezifische Optimierung Theoretisch: Performanter als statische Compiler Manche Optimierungen aus Zeitgründen nicht möglich Längere „startup“ Zeiten der Applikationen ngen.exe + - Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
20
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung SciMark Benchmark Fast Fourier Transformations (FFT), Successive Over-Relaxation (SOR), Monte-Carlo Quadrat, Sparse Matrix Multiplikation, LU Matrix Dekomposition v 1.1 MFLOP Architekturspez. Opt. Double-to-int cast (IA-32 SSE2) 300 200 MFLOP 100 1.0 1.1 HW: 2.4GHz Pentium 4, 256 MB RAM Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
21
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung CLR – automatische Speicherverwaltung „Allocation pattern“: GUT: Große Objekte, die am Programm- ende sterben Kleine, kurzlebige Objekte SCHLECHT: Viele Objekte überleben bis in Gen 2 und sterben „alte“ Objekte referenzieren „junge“ Objekte [1] Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
22
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung CLR – automatische Speicherverwaltung Maß für „Allocation Profile“: Performance counter: .NET CLR Memory: %in GC GUT < 30% SCHLECHT > 30% Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
23
.NET Performanzaspekte
Perf. Counters MS.NET C# Zusammenfassung Microsoft Shared Source CLI - „Rotor“ ECMA-334 (C#) ECMA-335 (Common Language Infrastructure) Microsoft Windows® XP FreeBSD SSCLI: Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
24
Weitere C# Tricks GC-freundliches Programmieren
Boxing, Werte/Referenztypen, Zeiger, Loops Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
25
Performanzaspekte von C#
Perf. Counters MS.NET C# Zusammenfassung GC & StringBuilder: Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
26
Performanzaspekte von C#
Perf. Counters MS.NET C# Zusammenfassung Loops foreach vs. for = Eleganz vs. Performanz Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
27
Performanzaspekte von C#
Perf. Counters MS.NET C# Zusammenfassung SciMark HW: 2.4GHz Pentium 4, 256 MB RAM Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
28
Performanz-orientierte Programmierung in C#
Zusammenfassung Perf. Counters MS.NET C# Zusammenfassung Profiling: „Performance Counter“ MS.NET CLR, GC, JIT C# Optimierungen GC-freundliches Programmieren Boxing, Werte/Referenztypen, Zeiger, Loops Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
29
Performanz-orientierte Programmierung in C#
Zusammenfassung Perf. Counters MS.NET C# Zusammenfassung MS.NET als High Performance Plattform Werkzeuge zur Performanzmessung und Analyse Ausdrucksstark Einfach (Übersichtlich) Effizienter Code Plattformunabhängigkeit; Portabilität Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
30
Fragen Vielen Dank für die Aufmerksamkeit! Haben Sie noch Fragen?
Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
31
Wie geht es weiter auf der STC…?
Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
32
Performanz-orientierte Programmierung in C#
Ressourcen msdn.microsoft.com msnews.microsoft.com Rotor: [1] Performance Considerations for Run-Time Technologies in the .NET Framework A .NET Developer Platform White Paper; Performanz-orientierte Programmierung in C# STC 02. – 03. Juni 2004
Ähnliche Präsentationen
© 2024 SlidePlayer.org Inc.
All rights reserved.