How can I create many objects quickly? In my application I have to create up to some 1000 tetraders (objects with 4 vertices, 4 faces, 6 edges). As input I get only the absolute vertex coordinates for each tetraeder. From the mathematical background I know that all tetraeders are identical but have a different location and rotation which I do not know.

The following code works (Tetra is some class providing the vertex coordinates of an tetraeder and some other informations which is not relevant here):

# object creation
def draw_Tetra(Tetra, Faces): 

    bm = bmesh.new()
    V1 = bm.verts.new(Tetra.Vertices[0])
    V2 = bm.verts.new(Tetra.Vertices[1])
    V3 = bm.verts.new(Tetra.Vertices[2])
    V4 = bm.verts.new(Tetra.Vertices[3])

    if Faces == True: 
        bm.faces.new((V1, V2, V3))  
        bm.faces.new((V1, V2, V4))
        bm.faces.new((V1, V3, V4))
        bm.faces.new((V2, V3, V4))        
    else: 
        bm.edges.new((V1, V2))
        bm.edges.new((V1, V3))
        bm.edges.new((V2, V3))
        bm.edges.new((V1, V4))
        bm.edges.new((V2, V4))
        bm.edges.new((V3, V4))  


name = "T_" + Tetra.Type + "_" + Tetra.pedigree
me = bpy.data.meshes.new(name)
bm.to_mesh(me)
bm.free
obj = bpy.data.objects.new(name,me)
scene = bpy.context.scene
scene.objects.link(obj)


However the script is extremely slow, e.g. to create 5000 tetraeders takes many hours. I think that I have the same problem as discussed here:

Python performance with Blender operators

The problem is that I do not know how to use "low level code" in this special situation. Can someone give me a tip?
Could also look at using from_pydata ? The following runs in 11 seconds on my Athlon pussbox.  Creating and freeing a bmesh for each new mesh seems a little overkill.

import bpy
import time


class Tetra():

    def object(self, scene):
        obj = bpy.data.objects.new("Tetra", self.mesh_from_pydata())
        scene.objects.link(obj)
        return obj

    def mesh_from_pydata(self):
        me = bpy.data.meshes.new("some_name")
        me.from_pydata(self.Verts, [], self.Faces)
        return me

    def __init__(self, verts):
        self.Verts = verts
        faces = []
        for i in range(4):
            faces.append([j for j in range(4) if j != i])
        self.Faces = faces

        pass


# test drive
context = bpy.context
scene = context.scene
start = time.time()
for x in range(5000):
    if not x % 100:
       print("Creating Object", x)
    tet = Tetra([(0.5,  0.5,  0.0), (0.5, -0.50, 0.0), (-0.5, 0.5,  0.0), (0.0,  0.0,  1.0)])
    obj = tet.object(scene)

end = time.time()
print("Done in %d seconds" % (end - start) )