Depends a bit on what kinds of racing you are thinking of. In MTB, there are cross-country (XC) and downhill racing, which doesn't really compare well to anything that BMX offers. XC events in particular is a lot longer than BMX races. But you can ride "dirt" with MTBs too, whic is fairly similar to BMX "dirt".
The BMX bikes that you buy at Target and or Walmart are not the same BMX bikes that are used in BMX Racing and BMX Freestyle. Real BMX bikes are lighter, they have diiferent size sprockets among many other things. Feel free to google the National Bicycle League or the American Bicycle League to get more information.