Monthly Archives: January 2014

Reader Mail – 01/19/2014 To 01/25/2014

Don Hoffman commented on About FSK.
I own a restaurant in Pennsylvania. I used to have live bands, karaoke, and djs. I was paying Ascap and BMI up til the end of 2012. I called ascap and bmi that i would be doing anymore live or recorded music. They had me fill out forms to that i have cancelled my account. Now come 2014, bmi calls and says i need to fill out another form which i did via email and fax. Then i had to do the same with ascap. Ascap comes back and says they can not cancel my account because i have tv's that are unmuted. They want bill me 1.28 per occupancy for music jingles from commercials or if a sporting event on tv is playing music. I told them i pay the cable companies for there service and direct tv for the nfl ticket. They said they own the copy rights to the music and i have public place. I am now taking the matter to my state representative and the better business bureau. Any suggestions on anything else i can do.

There isn't much you can do. Most of the TVs in restaurants are muted for precisely this reason. Sounds weird, but that's the way it is. The commercials pay for a license to use the music, but due to the bizarre way copyright law works, that doesn't also include the right for you to play it in your business.

Unfortunately, the music licensing cartels own Congress and the judges. Don't expect success. I know it's a drain on your business. Nonsense like this is one of the reasons the economy is so bad. Also, once you do sign a contract with the licensing cartels, they got you now. They'll make all sorts of excuses to prevent you from ending it, and the contract includes high interest rates and fees if you pay late.

One loophole that may work in your favor is that, if you have fewer than a certain number of speakers, you may not have to pay the fee.

Architect commented on Software Architects Suck - Never Trust A Software Architect.
Wow. This was pretty long winded.let's face it there are a lot of people in software that don't know what they're doing and can cover up their bullshit with documentation and politics.

I'm a software architect. But you know what, I earned that position and title through 15 years of hard work designing and implementing software solutions. I still write code. I still deploy software and automate processes. What I do that our developers don't is interface with clients, join sales calls as technical support, and lead our software evolution in a sustainable manner.

So get off your high horse as a developer. We know you've been in the trenches. Software is hard work, get over it. Realize that you own your own career and go work with people who will appreciate you and your skills.

Reader Mail – 12/29/2013 To 01/04/2014

Ken Carlson commented on About FSK.
I am a lawyer in the LA area, helping local restaurant owners in our little mountain village of Idyllwild, California, deal with ASCAP and BMI.

In 1966, the Justice Department criminally prosecuted BMI and ASCAP for Antitrust violations, and the plea bargain resolving those actions because euphemistically known as the "Consent Decree." In each of those cases, the organization is required to offer less than the "blanket" license to anyone who asks for it, like a restaurant. The goon squads that contact these small businesses defraud them by claiming that they have to pay the same as everyone else, but the Consent Decree says otherwise. If the parties cannot agree on a reasonable price, then the NY Dist. Court will take the case.

The Consent Decrees do not identify what kind of subset a given licensee might request, so I chose selected genres of music played in my clients' restaurants: jazz, folk, soft rock, etc. from given eras. ASCAP and BMI refused to give a license by genre, claiming that they have no way of doing that. Thus, for the past 3 years, my clients have paid nothing, waiting for the price BMI and ASCAP would offer. My clients continue to have music, and will only have to pay the reduced rate retroactively, if and when the issue is ever resolved. Rather than be shut down, we put BMI and ASCAP on the defense.

Defense? Absolutely. The Consent Decree requires them to treat all similarly situated licensees equally. If one of my clients pays only 5% of the blanket license, because they are only licensing that 5% of the entire repertoire, BMI and ASCAP's revenues go from $1000 per year to $50 per year, for example, from every such restaurant. If we get it, everyone else has to.

From another perspective, such a genre-based licensing would upset BMI and ASCAP's entire structure. Right now, since they don't know what songs are played in a restaurant, all of that money [with elevator music, shopping malls, stores, mechanic shops, etc] goes into the radio station pool, to be distributed based upon who is hot this week. We may play James Taylor songs in our restaurant, but Beyonce gets that money because of her air time. If BMI and ASCAP had to assign genres to their songs, the natural result would be mini-pools, where soft rock performers would want to get their share of the soft rock restaurant license money. The radio top 40 artists would be deprived of that income, and it would go to the rightful owners in at least a closer designation than the radio pool. When you consider that live music played in restaurants caters to the older crowd who can afford the entertainment restaurant, and that the catering means oldies, you would have all of the oldies performers suddenly getting royalties again, to their delight. Thus, the consumers win, the restaurant owners win, the artists win, and BMI and ASCAP bite the bullet.

When you consider the impact of millions of businesses demanding genre-based licenses at greatly reduces prices, it is billions of dollars in income shifting, and billions to the truly-entitled oldies artists. If you ask BMI and ASCAP, they flatly say it's impossible, since they have millions of songs in their database. However, if they simply set up a page on their site for the copyright owners to log in with an assigned username and password, they can assign their own genres to their songs, going directly into the database. I told them that they can hire a kid from a closed record store to help them assign genres, sine they feign inability. They also try to confuse the issue by saying that any song can be played in any style [the Triple Nickel case], but this is different: the song itself has an assigned genre, so if it's in the license of the restaurant, they can play it, and if not, not. What's the problem with that? They have no answer. The Department of Justice has not prohibited genre-based licensing, so it's only the BMI and ASCAP reluctance that creates the problem.

As long as they continue to defraud the public, saying that the restaurant MUST buy the blanket license, and that it is in violation of the Consent Decree to offer a lower price, the restaurants and other businesses paying protection money are just being shaken down. One irony is they they use their criminal plea bargain as the basis for their extortion. The other irony is that BMI and ASCAP are supposed to be helping their members, but since most of their repertoire are oldies, now, they're betraying their fiduciary duty to the vast majority of their members, and lining their own pockets with their commission from the overcharging.

Actually, it is now possible to write software that identifies a song being played. So, it would be easy to install a program that automatically analyzes each song played and charge per song. The licensing cartels do not do this, because they maximize their revenue by overcharging for a bulk license. The bulk license favors the songs that already hits, most of which are owned by the large corporations that back the licensing cartels.

Even though copyrights are issued to individuals, you typically have to sign away your copyright in order to get published. So, copyright is theoretically a system that promotes individual rights, but you have to sell those rights to the gatekeepers to get promoted. The Internet changes this somewhat, but the media cartel still has a lot of power.

If you know where to look, you can find royalty-free music. That's music you can legally play without paying any licensing fees. Maybe you should look into this and advise your clients to do this? If you made a collection of royalty-free music, along with a letter saying you legally reviewed it, that could be an interesting product.

The correct answer is "Intellectual property is not a valid form of property." Patents, copyrights, and trademarks all lead to legal extortion, as your clients are facing with music licensing. It was a mistake to allow them to be treated as property, but unfortunately that's the way the system is set up now.

commented on NFL Players Are Underpaid For The Playoffs And Super Bowl.
They can suck it up & play

Most have 1 catch the ball ..they make plenty & beyond

People are starving & they are buying guns girls cars for heck of it.

MP commented on FSK Benchmark Test - C/C++ vs. Javascript vs. PHP.
If you posted the code in all languages, maybe we could crowdsource optimizations?

Also, are you familiar with ASM.js? It could go a long way in FF.

Are you really interested? If someone's interested in doing that, I'll post it. The code only sort of works. It isn't polished.

Asm.js still isn't as fast as a native binary, but it'd be closer.

I do plan on finishing it, but I'll probably just have the calculation done on the server, with PHP doing a shell_exec to the C program.

It also would be interesting to try other languages, like Java, VB/C#.NET, Ruby, Python, etc. I still say that the C/C++ version would perform best.

MP commented on FSK Benchmark Test - C/C++ vs. Javascript vs. PHP.

*I'm* interested, but my career has been in C++, with a smattering of C# and Python. I have no serious Javascript experience.

OK, I uploaded my code. Here it is.

The Javascript is awful, because I wrote it before I learned jQuery. For the javascript version, you need the card images, so the page renders correctly in the client.

Hmm, the Javascript version runs faster when I turn Firebug off. I guess Firebug slowed it down a lot.

MP commented on FSK Benchmark Test - C/C++ vs. Javascript vs. PHP.

Just poking around at the C++ I get 250-300ms for each test (depending on targeting x86 v. x64, etc.) or about 8 million calls to evaluate_hand_96 per second (that's getting called about 2.6 million times). Which seems reasonable to me in raw numbers (this is on a 3.6 GHz i7, Win7x64, Visual Studio 2010), coming in at around 450 clock cycles per evaluate_hand_96. I tried running it through VTune Amplifier but I think the profiling doesn't give helpful results because the inner loops are so small that sampling isn't terribly useful. I tried removing the function pointers and converting some logical ops to arithmetic ones (I think I shaved off 50ms, but it could be a result of the optimization settings).

I've read the code enough to understand the structure, but I haven't looked to see why the inner loop is getting so many calls. Assuming that's really how much work needs to get done, I don't see an obvious way to tune it up without multithreading, etc.

I haven't looked at the other code yet (I will over the weekend), but you can contact me at the included email if you like.

1. Multithreading kind of defeats the purpose, because I want to compare Javascript, PHP, and C/C++.

1.a. When I want to run it to loop over every hand and make a full strategy table, I can do multiple processes.

2. I think that's one advantage of C++ with full optimization. It inlines the functions.

Also, Visual Studio, when you compile for release, automatically turns on full optimization for you. With gcc, I had to remember to do that myself on the command line.

3. The overhead for a function call is MUCH LESS in C/C++, compared to Javascript or PHP. (especially for code like this, where I'm not allocating many variables or using the heap)

4. If you optimize the code in one language then, to make it a fair comparison, it has to be optimized in each language. I thought that the exact same algorithm in each language would be the most valid comparison.

The inner loop gets so many calls because, when you draw 5 cards, it needs to evaluate 47*46*45*44*43/5! possibilities for what you could draw. When you draw 4 cards, it needs to evaluate 47*46*45*44/4! possibilities. That's a lot of iterations. Drawing all 5 cards is stupid sometimes, like when you have a pair, but for completeness I always check every possibility.

Also, I put the function pointers in, because I want the same code to work with multiple video poker variants. I'm also doing Double Joker Wild, which means a completely different function to evaluate the hand. Other video poker variants give a bonus for certain 4-of-a-kinds, which also would require a completely different evaluation function.

MP commented on FSK Benchmark Test - C/C++ vs. Javascript vs. PHP.

Yah, I figured that sounded like it was about right for the combinatorics, but doing a quick calculation of 47 choose 5 comes up with 1.5e6 not 2.6e6. I figured multi-threading was out for purposes of comparison, and that any optimization for one language should be for all--I just tackled first what I know best.

47_choose_5 is 1.5E6. 47_choose_4 is 1.7e5, but you draw 4 cards 5 times (5 different possibilities for holding one card).

When I do the double joker wild variant, it'll be a 54 card deck.

Also, I don't want the code to take shortcuts, by making assumptions such as "always hold a pair". In some video poker variants (especially with wild cards), a pair is a bad hand to hold. I could take shortcuts by making the code more intelligent, but that would limit the ease of modifying it for various video poker variants.

FSK Benchmark Test – C/C++ vs. Javascript vs. PHP

Very frequently, you read benchmark claims for various languages. Those claims have lots of problems. First, they usually are a “Hello, world!” program, and not complicated business logic. Second, they usually compare optimized code in X vs. poorly written Y.

I decided to write a “Video Poker Trainer” program. In video poker gambling, you are dealt 5 cards. You choose what cards to hold, and then draw new cards. Based on your final hand, you receive a payout.

Some video poker games have a payout close to 100%, but the strategy is complicated. The casino advantage comes from the fact that many people make suboptimal plays. Therefore, it would be useful to have a program that helps you practice.

My program solves the video poker hand by checking all the possibilities. There are 2^5=32 possibilities for what you hold, and then 47_choose_n possibilities for draws, where n is the number of cards you draw. I wasn’t intending to do this as a benchmark test, but when the performance of my first version was unacceptable, I wound up rewriting it in several languages.

All of this code is running on my desktop PC.

My first try was Javascript. My goal is to make a browser game. To solve one hand, it took 48 seconds in Firefox, which is unacceptable performance for an interactive game.

I then tried Chrome (V8). There, it took 1.6 seconds! That’s a substantial difference compared to Firefox!

However, 1.6 seconds is still unacceptable for a game. The browser window would freeze while the calculation ran. I could sprinkle SetTimeout during the calculation, but that would make it take even longer. Also, if it’s a browser game, I can’t assume that the client is using Chrome.

I rewrote the code in PHP. It was the exact same algorithm, changing Javascript syntax to PHP syntax and leaving it otherwise the same. (I did make some minor enhancements. The Javascript version had a hardcoded hand evaluation function and paytable. The PHP version used function pointers and a paytable parameter, so it could support different games.)

I was shocked that the PHP version took 3 minutes! I thought PHP would beat Javascript, but it was worse!

I could have tried HVVM (Facebook’s version of optimized PHP), but didn’t.

My final try was C/C++. I expected that C would clobber everything, including Chrome/V8. Again, it was the exact same algorithm, changing the PHP syntax to C/C++ syntax.

I was surprised that the C/C++ version took 1.6 seconds, the same as Chrome/V8! I was pretty shocked by that.

I probably could go back and tune the code, but to be fair, then I’d have to do it in all 3 languages. To make the comparison perfectly accurate, it should be the exact same algorithm in each language.

It wouldn’t be a proper experiment if I got the answer I expected. I thought that the C version would clobber everything, including the Chrome/V8 version. Instead, C and Chrome came out tied.

Oops, just as I finished this post, I realized I made a mistake. I was using gcc WITH THE DEFAULT COMPILE OPTIONS! I tried again with -O3 full optimization flags! Now, the C version takes 0.6 seconds, coming out ahead of V8, like it should. My confidence in C is restored. (For completeness, -O1 took 0.71 seconds, -O2 0.61 seconds, -O3 0.60 seconds.)

Another improvement, “gcc -O3 -ffast-math” took 0.57 seconds! (I don’t mind an error in the 7th decimal place, since this is a game, so -ffast-math is a reasonable compiler optimization.)

The benchmark comparison was on my desktop. Moving to my Linode (using g++ instead of gcc), the unoptimized version took 1.3 seconds per hand. The -O3 version took 0.36 seconds per hand! (Actually, because the Linode is shared, the time it takes to run depends on how much the other users are using the server. I got a range of 0.36 seconds per hand to 0.5 seconds per hand.)

My initial conclusion, as I was composing this post, was that Chrome/V8 and C had equal performance. However, I was making a big mistake! I wasn’t turning on optimization settings in gcc! That shows how a poorly conducted benchmark test can lead to false conclusions. I almost made that mistake myself! (For Chrome/V8, I was using the default settings. I don’t know anything about extra optimization settings in Chrome/V8.)

The game still isn’t finished. I just wrote the code that does the calculations. I’ll put it up here when I”m done. It looks like only way to get acceptable performance is to shell_exec call the C program that does the calculation, and then serve that to the client. If I’m just calling an external C program, it doesn’t matter what language I use on the server, but I’m going to stick with PHP because that’s what I like the best.

It’s also educational to write the same algorithm in multiple languages. By the time I got around to the C/C++ version, I was making sure it was proper reusable code, so I could use the same function to solve multiple video poker variants. I plan for my actual program to work on 9/6 and Double Joker Wild. (Double Joker Wild and 9/6 are two video poker variants. 9/6 has a house edge of only 0.6% played perfectly, and Double Joker Wild has a house edge of 0.09% played perfectly, making a practice program useful. Adding wild cards means I need a completely different hand evaluation function, which is why I had to make that a function pointer.)

I made a benchmark comparison of C/C++, Javascript, and PHP, by writing the exact same algorithm in 3 languages and comparing the run time. The code was exactly the same, merely changing the Javascript syntax to PHP or C/C++. Surprisingly, PHP was the worst, taking 3 minutes to solve one hand. Firefox Javascript came in second at 48 seconds, still horrible. Chrome/V8 and unoptimized C/C++ came in tied at 1.6 seconds. I almost came to the false conclusion that Chrome/V8 and C were equal, because I forgot to turn on optimization in gcc. When I turned on full optimization in gcc, the C version took 0.60-0.57 seconds per hand, which is nearly 3 times faster than Javascript. As I expected, C/C++ was the fastest, but only when I remembered to turn on compiler optimization.