Kill people, win matches ,complete challenges. That's a good nutshell way to put it but really the easiest way to level is to gain XP. If you're constantly switching to the new gun you just unlocked it's going to be slower because the rewards you receive from unlocking most/all of the attachments yield relatively good xp. Also there are challenges like "rival" and extreme cruelty. If you can complete most of these challenges you'll find yourself accumulating levels at a higher rate than if you cold shoulder the challenges and leave weapons attachments half completed. If find a gun (like the TAR - 21) that I like and at least unlock the Blue Tiger Stripes. Also you get more points for double kills and headshots.
Use Specialist. After you unlock the first perk, every kill is double xp from there.
Use all attachments on weapons to complete the challenges for them.