first of all, as i mentioned above, how much the end product is worth has very little to do with what it costs you in energy to grow it!
Market value is determined by supply and demand, which is is to a large part dependent on where you are geographically. Even though electricity literally costs on average twice in california, what it does in north dakota, the price of weed is still probably going to be lower in california, because there is a legal/gray market industry in ca and a much better supply. If you're in mexico, again, there is so much pot grown outside, and the economy is so lousy, that once you factor in equipment costs and the value of your time, you literally may be able to buy commercially grown weed cheaper than you can grow it yourself indoors.
In terms of measuring your costs, you just use simple arithmetic.
A "quick and dirty" estimate of your power cost per crop would be the nominal power rating of your lamps x hours burned x cost per hour as an estimate of how much energy you're using.
for example, if you're growing under a 400w hps, then you're using roughly 400 watts per hour, or 0.4 kilowatts/hr. If your grow cycle is 30 days of seedling/veg at 24-0 then 60 days of flower at 12-12, then your lamp will be on a total of 1440 hours for that grow cycle. 1440 hours x 0.4 kw/h = a total draw of 576 kilowatts for lighting the entire grow.
If you're paying 12 cents per kilowatt-hour for electricity (which is close to the national median) for power, then you'll have used a total of $69.12 worth of electricity over your 90 day grow cycle, or roughly $23 per month. Whether or not that extra $23 will be a noticeable increase in your monthly bill is going to depend largely on the size of that bill. If you're living in a small apt by yourself, you'd probably notice the difference. If you are living in a large house with several other people, probably not.
If you want to estimate energy cost/gram, you could take your total energy cost in dollars, then divide it by the total harvest yield in grams.
Now, realistically, computing total costs is a little more complicated than that.
and dont
forget the people on teird rating.. Who pay triple or quadruple if they go over a base line usage that is alolotted for each residence
in terms of true energy use, you have to also count the energy used by your lamp ballasts (which add roughly 10% more on top of bulb energy use), by fans or other cooling, by any timers you may be running, and by any pumps or other hydroponics devices. Together those could easily add another 15-20% to total energy used. If you want to know the exact amount of energy any device uses, there are meters you can buy that will directly measure current/energy draw of any particular device plugged into them, and doing it that way is a lot better than trying to read the amounts from your home electricity meter.
Also, if you really want to know your true material cost per grow, there is more to it than energy cost. You also have to include your cost for seeds, soil, pots, water, nutrients, light bulb depreciation, odor control and/or other security. You will also need to count your "setup costs" (ie costs of lights, fans, bulbs, etc), though that cost could fairly be amortized over multiple grows.
Total cost = your material cost (seeds, soil, pots, water, nutes, equipment cost amortized over number of grows, bulb replacement cost) + energy cost + value of your time x hours worked.
Divide your total cost by your total harvest yield weight in grams to give the true production cost per gram.
Note that if you're otherwise busy, or your time is really valuable, it may not "pay" for you to grow your own weed, again explaining why it makes perfect sense for some people to pay $400 an ounce for weed that on paper "could" be produced at only $30/oz materials and energy costs. If you want the stuff today, instead of 4 months from now, growing may not make sense. Also, if you're not regularly consuming large amounts of it, it simply may not be worth it for you to you to go to the trouble, take the time, and incur the startup costs of setting up your own garden and learning how to grow.
Again, just because its easy for some people to grow their own weed for only a few dollars per ounce, doesn't mean that its practical for everyone to do that.