2014 - Ben Watson - Writing High Performance .NET Code.pdf

(3581 KB) Pobierz
Writing
High-Performance
.NET Code
Ben Watson
Writing High-Performance .NET Code
Version 1.4
PDF Edition
ISBN-13: 978-0-9905834-2-4
ISBN-10: 0-99058-342-2
Copyright © 2014 Ben Watson
All Rights Reserved. These rights include reproduction, transmission, translation, and electronic
storage. For the purposes of Fair Use, brief excerpts of the text are permitted for non-
commercial purposes. Code samples may be reproduced on a computer for the purpose of
compilation and execution and not for republication.
This eBook is licensed for your personal and professional use only. You may not resell or give
this book away to other people. If you wish to give this book to another person, please buy an
additional copy for each recipient. If you are reading this book and did not purchase it, or it was
not purchased for your use only, then please visit
http://www.writinghighperf.net/buy/
and
purchase your own copy. If you wish to purchase this book for your organization, please contact
me for licensing information. Thank you for respecting the hard work of this author.
Trademarks
Any trademarked names, logos, or images used in this book are assumed valid trademarks of
their respective owners. There is no intention to infringe on the trademark.
Disclaimer
While care has been taking to ensure the information contained in this book is accurate, the
author takes no responsibility for your use of the information presented.
Contact
For more information about this book, please visit www.writinghighperf.net or email
feedback@writinghighperf.net.
Cover Design
Cover design by Claire Watson, http://www.bluekittycreations.co.uk.
Table of Contents
Table of Contents ................................................................................................................... i
About the Author ................................................................................................................. vii
About the Technical Editor .................................................................................................. viii
Acknowledgements............................................................................................................... ix
Introduction ..........................................................................................................................1
Purpose of this Book.................................................................................................................... 1
Why Should You Choose Managed Code? .................................................................................. 3
Is Managed Code Slower Than Native Code? .............................................................................. 5
Am I Giving Up Control? .............................................................................................................. 6
Work With the CLR, Not Against It .............................................................................................. 6
Layers of Optimization................................................................................................................. 7
Sample Source Code .................................................................................................................... 9
Why Gears? ................................................................................................................................. 9
1 Performance Measurement and Tools ............................................................................... 11
Choosing What to Measure ....................................................................................................... 11
Average vs. Percentiles.............................................................................................................. 13
Measurement Tools................................................................................................................... 15
Summary.................................................................................................................................... 42
2 Garbage Collection ............................................................................................................ 45
Basic Operation ......................................................................................................................... 48
Configuration Options ............................................................................................................... 52
Reduce Allocation Rate ............................................................................................................. 55
i
Zgłoś jeśli naruszono regulamin