A Boeing Co. T-X trainer aircraft is seen at the Boeing Defense, Space & Security facility in St. Louis, Missouri, U.S., on Monday, July 24, 2018.

It's been two years since Donald Trump was inaugurated as president of the United States. In that time, defense and tech stocks, have blown everybody out of the water.

The iShares U.S. Aerospace & Defense (ITA) exchange-traded fund has surged more than 30 percent since Jan. 19, 2017. The S&P 500 tech, meanwhile, has spiked more than 37 percent in that time. Both sectors have easily outperformed the , which is up 18 percent.

Gains in the ITA have been largely driven by surges in Boeing, AeroVironment and Aerojet Rocketdyne. Those three stocks have more than doubled over the past two years. Other high-flying stocks in the defense sector these past two years have are Axon Enterprise — which is up nearly 100 percent in that time — and Heico Corp., which has risen 97 percent.

In tech, Arista Networks is the best performer, surging more than 150 percent. Red Hat and Adobe have also more than doubled in that time, along with PayPal and Advanced Micro Devices.

Defense and tech stocks are not the only ones that have done well these past two years. The S&P 500 health care sector up more than 26 percent since Trump was inaugurated, led by a Nektar Therapeutics. The stock has almost quadrupled in that time, gaining nearly 280 percent, and is the best performer in the S&P 500. Abiomed, another health-care stock, is the second-best performer in the S&P 500, gaining about 200 percent. NRG Energy, Netflix and Arista Networks round out the five-best performers in the S&P 500.

Not all stocks have performed well over the past two years, however. The energy and communication services sectors are both down more than 13 percent in that time.

Subscribe to CNBC on YouTube.