Scott Hanselman

Benchmarking .NET code

February 25, '16 Comments [28] Posted in Open Source
Sponsored By
You've got a fast car...photo by Robert Scoble used under CC

A while back I did a post called Proper benchmarking to diagnose and solve a .NET serialization bottleneck. I also had Matt Warren on my podcast and we did an episode called Performance as a Feature.

Today Matt is working with Andrey Akinshin on an open source library called BenchmarkDotNet. It's becoming a very full-featured .NET benchmarking library being used by a number of great projects. It's even been used by Ben Adams of "Kestrel" benchmarking fame.

You basically attribute benchmarks similar to tests, for example:

[Benchmark]
public byte[] Sha256()
{
return sha256.ComputeHash(data);
}

[Benchmark]
public byte[] Md5()
{
return md5.ComputeHash(data);
}

The result is lovely output like this in a table you can even paste into a GitHub issue if you like.

Benchmark.NET makes a table of the Method, Median and StdDev

Basically it's doing the boring bits of benchmarking that you (and I) will likely do wrong anyway. There are a ton of samples for Frameworks and CLR internals that you can explore.

Finally it includes a ton of features that make writing benchmarks easier, including csv/markdown/text output, parametrized benchmarks and diagnostics. Plus it can now tell you how much memory each benchmark allocates, see Matt's recent blog post for more info on this (implemented using ETW events, like PerfView).

There's some amazing benchmarking going on in the community. ASP.NET Core recently hit 1.15 MILLION requests per second.

That's pushing over 12.6 Gbps a second. Folks are seeing nice performance improvements with ASP.NET Core (formerly ASP.NET RC1) even just with upgrades.

It's going to be a great year! Be sure to explore the ASP.NET Benchmarks on GitHub https://github.com/aspnet/benchmarks as we move our way up the TechEmpower Benchmarks!

What are YOU using to benchmark your code?


Sponsor: Thanks to my friends at Redgate for sponsoring the blog this week! Have you got SQL fingers?Try SQL Prompt and you’ll be able to write, refactor, and reformat SQL effortlessly in SSMS and Visual Studio. Find out more with a free trial!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The Joy of Live Coding - CodePen, REPLs, TOPLAP, Alive, and more

February 17, '16 Comments [29] Posted in Open Source
Sponsored By

A few weeks ago I talked about Interactive Coding with C# and F# REPLs. There's a whole generation that seemingly missed out on LIVE CODING. By that, I mean, writing and running code at the same time.

Lots of folks used C, C++, Delphi, C#, Java, etc over the last 15-20-30 years and had a pretty standard Write, Compile, Walk Away, Run process working for them. Twenty years ago I was often waiting 30 min or more for stuff that takes seconds now. Many of you today may have to wait hours for compilation.

However, there's so many environments available today that can allow us to write code while it runs. Instant satisfaction...and the browser is becoming a fantastic IDE for Live Coding.

When I use the term "Live Coding" though, there's actually a couple of definitions. I'm conflating them on purpose. There's Live Coding as in "coding LIVE while people watch" and there's "coding and watching your program change as you type." Of course, you can do them both, hence my conflating.

Live Coding - Music and Art

Mike Hodnick mentioned Live Coding to me in the context of music and art. Live Coders use a wide array of languages and tech stacks to make music and art, including JavaScript, Ruby, Haskell, Clojure, and a number of DSL's. Here is a YouTube video of Mike - Live Coding music using Tidal, a language for musical improvisation.

Resources

  • Overtone - Collaborative Programmable Music.
  • TOPLAP - An organization dedicated to live coding.
  • Cyril - Live Coding Visuals
  • SuperCollider - Real time audio synthesis
  • Tidal - Live Coding Music

Some prominent live coders:

Live Coding - JavaScript and Experimentation

There's another kind of live coding that makes me happy, and that's things like CodePen. Sometimes you just want to write some HTML, CSS, and/or some JavaScript. No IDEA, no text editor...AND you want it to be running as you type.

Code and Watch. That's it.

Some of you LIVE in CodePen. It's where most of your work and prototyping happens, truly. Others who read this blog may be learning of CodePen's existence this very moment. So don't knock them! ;)

CodePen is lovely

CodePen is a "playground for the front-end side of the web." There have been a number of Live Coding Playgrounds out there, including...

But it's fair to say that CodePen has stayed winning. The community is strong and the inspiration you'll find on CodePen is amazing.

Oh, and just to end this blog post on a high note, ahem, and combine Live Coding of Music with  ahem, here's a Roland 808 (that's a Rhythm Controller) written entirely in CodePen. Ya, so. Ya. And it works. AWESOME. Here's the code you can play with, it's by Gregor Adams.

Magical Roland 808 written in CodePen

There's even Live Coding in Visual Studio now with the "Alive" plugin at https://comealive.io.

What kinds of Live Coding tools or experiences have YOU seen, Dear Reader? Share in the comments!


Sponsor: Thanks to my friends at Redgate for sponsoring the blog this week! Have you got SQL fingers? Try SQL Prompt and you’ll be able to write, refactor, and reformat SQL effortlessly in SSMS and Visual Studio. Find out more with a free trial!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

GitHub Activity Guilt and the Coder's FitBit

February 9, '16 Comments [58] Posted in Open Source
Sponsored By

I got an interesting email today from Corey P., reprinted in part here, with permission.

I’m curious, how you feel about GitHub’s activity graph? I’ve found myself getting increased levels of guilt/stress over that graph. So much so I’m considering not using GitHub for personal projects (only use it for contributing pull requests, reporting issues, etc.). 

I can’t help but feel like others judge me by it (phony syndrome?). I have this gnawing feeling that I need to do something in the open so I can have some sort of paper trail or else I’ll be looked down upon by people (perspective employers? colleagues?).

This is a great question. Let's look at my GitHub Graph.

235 Total Contributions

Yikes. Is this good or bad? It's pretty spartan over Sep-Nov, although I was travelling a lot.

Maybe Damian Edwards? He leads ASP.NET, although he isn't technically a dev (as far as HR is concerned). He's got me beat by double.

564 Total Contributions

OK, what's a serious contender look like? Here's Monica Dinculescu, Googler and dev on Polymer:

3244 Total Contributions

or David Fowler, architect and dev on ASP.NET

1885 Total Contributions

What's our takeaway here? That I suck and Monica's amazing? (True, though, I do suck, and please have a listen to Monica as she explains Web Components to me on a recent podcast episode)

Here's what I think about charts like this, and I'm interested in your opinion.

  • GitHub's activity chart shows public repos, not private activity.
  • I have a lot of small projects I work on during the week in private or local repos. and sometimes I don't make them public due to (slight) embarrassment at my works in progress.
  • It's not always healthy to measure yourself against others, particularly if it makes you feel bad or is somewhat unhealthy.
  • Jobs vary. Being a manager does take you away from coding sometimes.
  • If it bothers you, set a reasonable goal and work towards it, but do it for a good reason. (See how Reason and Reasonable factor in greatly there?)

Will I ever be as prolific as Monica or David? Likely not, but it's cool to know what the top of the bar is. Also, we have different jobs. Monica is working actively on a public open source project, while I'm not currently committing code to ASP.NET Core. Even Damian, a Lead PM on ASP.NET Core gets caught up in the "management" of it all. I doubt he gives his green chart a second thought.

My job currently doesn't have me committing to public repros as often as I'd like, but I'm not going let this chart dictate my value to the team. I will use it as one of many measuring sticks and I'd encourage you to as well. Perhaps set a goal to commit to an OSS project a few times a week?

GitHub Acitivty as it relates to Hiring

Sasha Laundy brought up a number of important points on Twitter about your GitHub Activity graph. She says:

If GitHub commits are only side projects, what kinds of people have time to put towards that? and if you can be silently discredited in hiring because of your public profile, how does that impact equity & diversity?

She has a great point. It's worth arguing that given the GitHub Activity Graph shows only public activity, making judgments based on it would naturally skew towards:

  • The already skilled vs. the codenewbie
  • People with more spare time, e.g. young, single, etc
  • Folks who work on OSS full-time (their company pays them to commit publically to code)

To her point, if your GitHub Activity page is given similar weight as your LinkedIn, how will you ever know if you've been quietly excluded from a job based on this chart? If you're just getting started or if you're a 20 year Enterprise software developer you may end up with an empty graph and find an uninformed recruiter glossed over your potential or experience based how much "green" they see.

What do YOU think of this? Does your GitHub Activity Graph stress you out like getting 10,000 steps on your FitBit? Or do you just roll with it? Sound off in the comments.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Interactive Coding with C# and F# REPLs (ScriptCS or the Visual Studio Interactive Window)

January 29, '16 Comments [37] Posted in Open Source
Sponsored By

REPLs are great! REPL stands for Read–eval–print loop and is pronounced "REP-L" quickly, like "battle." Lots of languages and environments have interactive coding and REPLS at their heart and have for years. C# and F# do also, but a lot of people don't realize there are REPLs available!

ScriptCS

In 2013 once the Roslyn open source C# compiler started to mature, Glenn Block and many friends made ScriptCS. It now lives at http://scriptcs.net and has a great GitHub and active community. The Mono project has also had a REPL for a very long time.

The C# Interactive Shell CSI

You can install ScriptCS in minutes with the Chocolatey Package Manager or OneGet with Chocolatey on Windows 10. In the screenshot above I'm writing code at the command prompt, making mistakes, and fixing them. It's a great way to learn and play with C#, but it's also VERY powerful. You can create C# Scripts (.csx files) kind of like PowerShell but it's just C#!

Visual Studio's REPLs - CSI and FSI

The Visual Studio team meets/met with the ScriptCS folks in the open and even publishes their meeting notes on GitHub! In May of last year they got ScriptCS working in OmniSharp and Visual Studio Code, which is amazing. There's a great set of directions here on how to set up ScriptCS in Visual Studio Code and the code is moving fast on GitHub.

Visual Studio 2015 Update 1 has REPLs within the IDE itself. If you have Visual Studio 2015, make sure you've updated to Update 1. If you don't have VS, you can get the free Visual Studio Community at http://visualstudio.com/free.

VS ships a command line RELP called "CSI" that you can use to run ".csx" scripts as well. Turns out the source code for CSI is basically nothing! Check it out at http://source.roslyn.io/#csi/Csi.cs and you can see how easy it would be for you to add scripting (interactive or otherwise) to your own app.

C# Interactive REPL inside Visual Studio

There's a great C# Interactive Walkthrough by Kasey Uhlenhuth that you should take a moment and play with. She's the Program Manager on this feature and also has a great video on Channel 9 on how to use the C# Interactive REPL.

Introducing the Visual Studio 'C# REPL'

Of course, F# has always had a REPL called "fsi.exe" that also ships with VS. You may have this on your PATH and not realize it, in fact. F# script files are ".fsx" so there's a nice symmetry with scripting and REPLs available in both languages, either in VS itself, or at the command line.

The F# Interactive Shell

F#'s REPL is also inside VS, right here next to the C# Interactive Window.

C# Interactive and F# Interactive in VS

These are all great options for learning and exploring code in a more interactive way than the traditional "write, compile, wait, run" that so many of us are used to.

Let's hear in the comments how (or if!) you're using REPLs like these two make your programming life better.


Sponsor: Big thanks to Wiwet for sponsoring the feed this week. Build responsive ASP.NET web appsquickly and easily using C# or VB for any device in 1 minute. Wiwet ASP.Net templates are integrated into Visual Studio for ease of use. Get them now at Wiwet.com.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Review: littleBits Gadgets and Gizmos electronics kits for STEM kids

January 21, '16 Comments [13] Posted in Parenting
Sponsored By

GGK_Box_Everything_600x400_v-2I love posting about STEM (Science, Technology, Engineering, and Mathematics) and some of the great resources, products, and software that we can use to better prepare the next generation of little techies.

Here's some previous posts I've done on the topics of STEM, kids, programming, and learning with young people:

The 8 year old (recently 7, now barely 8) has been playing with littleBits lately and having a blast. He loved SnapCircuits so littleBits seemed like a reasonable, if slightly higher-level, option.

SnapCircuits boldly has kids as young as three or four creating circuitry from a simple light and switch all the way up to a solar-powered radio or a burglar/door alarm. It doesn't hide the complexities of volts and amps and includes low-level components like resistors. Frankly, I wish my first EE (Electrical Engineering) class in college was taught with SnapCircuits.

LittleBits (usually a lowercase L) jumps up a layer of abstraction and includes motors, motion detectors, LED arrays, and lots more. There are also specific kits for specific interests like a littleBits Musical Electronics Synth Kit and a littleBits Smart Home Kit that include specific littleBits that extend the base kit.

littleBits1

The key to littleBits is their magic magnet that makes it basically impossible to do something wrong or hurt yourself. The genius here is that the magnet only goes one way (because: magnets) and the connector underlying transmits both power and data.

You start with a power bit, then add an "if" statement like a switch, then move to do a "do" statement like a motor or light or whatever. In just about 20 minutes my 8 year old was able to take a LEGO custom Star Wars Blaster and add totally new functionality like lights and sounds..

The 8 year old wanted to show his Star Wars Blaster/Fan combo made with @littlebits #video

A video posted by Scott Hanselman (@shanselman) on


One of the aspects of littleBits that I think is powerful but that wasn't immediately obvious to me is that you shouldn't be afraid to use glue or more permanent attachments with your projects. I initially tried to attach littleBits with rubber bands and strings but realized that they'd smartly included "glue dots" and Velcro as well as 3M adhesive pads. Once we stopped being "afraid" to use these stickers and adhesives, suddenly little projects became semi-permanent technical art installations.

We got the "Gizmos & Gadgets" kit which is a little spendy, but it includes 15 bits that enables you to do basically anything. The instructions are great and we a had remote-controlled robot that could drive around the room running within an hour. It's a great setup, a fun kit, and something that kids 8-14 will use all the time.

Here are some fantastic examples of other Star Wars related littleBits projects for you to explore:

*Amazon links are referral links on my blog. Click them and share them to support the blog and the work I do, writing this blog on my own time. Thanks!


Sponsor: Big thanks to Wiwet for sponsoring the feed this week. Build responsive ASP.NET web apps quickly and easily using C# or VB for any device in 1 minute. Wiwet ASP.Net templates are integrated into Visual Studio for ease of use. Get them now at Wiwet.com.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.